• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime.exec() doesnt seem to work.

 
arvind s
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
p.waitFor();
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
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac writes to the error stream and not the standard outputstream. Change your code
InputStream is = p.getInputStream();
to
InputStream is = p.getErrorStream();
And it should work.
Hope this helps
 
arvind s
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Carl,
It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic