Hi Adam and welcome to the Ranch! First, it's good that you started a new thread, some of the classes and methods you would use today weren't around when that question was asked... SwingWorker comes to mind. Secondly, what's a jTextBox?
There are no new questions, but there may be new answers.
Joined: Jun 24, 2011
Darryl Burke wrote:Hi Adam and welcome to the Ranch! First, it's good that you started a new thread, some of the classes and methods you would use today weren't around when that question was asked... SwingWorker comes to mind.
All updates to the JTextArea should be done on the Event Dispatcher Thread. The Javadoc says that JTextArea.append is thread-safe but it isn't; the Java 7 Javadoc fixes that.
With SwingWorker you could do the bulk of the work in doInBackground(). When you read a line you don't append it directly but instead you publish it. You override the process method to append all lines you've published.
With a regular Runnable / Thread you would need to use EventQueue.invokeLater (or SwingUtilities.invokeLater; this merely calls the former) for each line you need to append.
Now, I see two problems with your code:
1) readLine strips away the line breaks, so those will be missing from the JTextArea. You need to add them manually again.
2) you now read the input and error streams consecutively. This could still lead to deadlock when the process' error stream buffer becomes full and the process just stops (see When Runtime.exec() won't). You really need to a) read them concurrently, or b) use ProcessBuilder and call redirectErrorStream(true) on it, in which case you can ignore the error stream afterwards.