File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Runtime.exec() doesnt seem to work. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Runtime.exec() doesnt seem to work." Watch "Runtime.exec() doesnt seem to work." New topic

Runtime.exec() doesnt seem to work.

arvind s

Joined: Dec 18, 2000
Posts: 6
I am trying to write an application in which :-
1)I write a text file in a textarea(possibly java code).
2)I save the file to a filename with the help of 'SAVE' option
in the application itself.
3)Now i want to send the command'javac filename' to the DOS prompt and get back the output from the DOS prompt and paste it on to a text area.
4)Process p = Runtime.getRuntime().exec("command /c " + "javac " + filename);
InputStream is = p.getInputStream();
BufferedReader br =new BufferedReader(new InputStreamReader(is));
while(br.readLine() != null)
{ txtarea.append(br.readLine()); }
5) But this is not working. The textarea still remains blank.
Whereas what i want is the ouput of the compilation on the textarea.
6)My OS is Win 98.
7)Thanks in advance.
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
javac writes to the error stream and not the standard outputstream. Change your code
InputStream is = p.getInputStream();
InputStream is = p.getErrorStream();
And it should work.
Hope this helps

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
arvind s

Joined: Dec 18, 2000
Posts: 6
Thanks Carl,
It worked.
I agree. Here's the link:
subject: Runtime.exec() doesnt seem to work.
It's not a secret anymore!