This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Runtime.exec() doesnt seem to work." Watch "Runtime.exec() doesnt seem to work." New topic
Author

Runtime.exec() doesnt seem to work.

arvind s
Greenhorn

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);
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

Joined: Jun 13, 2000
Posts: 3340
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


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

Joined: Dec 18, 2000
Posts: 6
Thanks Carl,
It worked.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Runtime.exec() doesnt seem to work.
 
Similar Threads
Writting confirmation message??
Creating a RMI text editor???
How to reassign STDIN to a JTextArea??
how to copy files form server to local path?
Writting confirmation message??