Reading realtime stdout/stdin
843829Mar 5 2003 — edited Mar 9 2003Hi 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