Josh "hit en end-of-file condition" what does that mean?
And i tried out a code ..but not had fruitful result.
I am using Windows ..now i came to know that runtime.exec behaves OS specific .
-
Process l_p = Runtime.getRuntime().exec("javac");
-
InputStream output = l_p.getInputStream();
-
InputStream error = l_p.getErrorStream();
-
BufferedReader _output_ = new BufferedReader(new InputStreamReader(output));
-
BufferedReader _error_ = new BufferedReader(new InputStreamReader(error));
-
String line = null;
-
while((line=_output_.readLine())!=null) System.out.println(line);
-
while((line=_error_.readLine())!=null) System.out.println(line);
-
System.out.println("Exit Code: " + l_p.waitFor());
-
Here my program hangs, and if i comment the reading of input(output of javac) then it works .how?
I thought you said you understood what I wrote? When you exec just "javac" it
tries to print an helpful page to stderr (try it manually!). You first try to read what
came out of the process' stdout stream (nothing) but that stream doesn't hit any
end-of-file condition; there just isn't any output to stdout so your first loop never
terminates and you never start the second loop.
You need separate threads for the reading on any output stream of the exec'd process.
If you know how the process behaves you can anticipate on its behaviour but in
general you need separate threads for the reading part.
kind regards,
Jos