Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading realtime stdout/stdin

843829Mar 5 2003 — edited Mar 9 2003
Hi All,

Hoping there's a quick answer to this one...

I have a perl script that is producing output as it runs, its a quite a long script, and I would like to display that output in a JTextArea on a swing GUI as it runs.

At the moment I'm using a BufferedReader to read the output of the command run through a Process Object.


Process p = Runtime.getRuntime().exec(command);

return new BufferedReader(new InputStreamReader(p.getInputStream()));


Which I read with

while (true) { System.out.println("Reading\n");
String output = scriptReader.readLine().trim() + "\n";
gettpLog().append(output);
}


This waits until the script finishes then dumps the entire contents of the buffer to the JTextArea.

QUESTION - does anyone know how to have this dump to the JTextArea as it happens, i.e. near realtime, so that a user of the GUI can watch the outputs as the script runs?

Is a BufferedReader my best option here?

Many Thanks

Matt
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2003
Added on Mar 5 2003
2 comments
281 views