My project aims to integrate a terminal into a Swing App. The problem is that some blocking commands are blocking the stream. That is why I would like to read with a buffer into the Standard output with a thread in order to "unblock" the input stream.
My question is similar to this topic, Why is my JTextArea not updating?
I apply what they said: using a thread in order to update my JTextArea
.
public void appendNewText(String line) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
outputComponent.setText(outputComponent.getText() + line + "\n");
}
});
}
this.outputComponent.setText("");
processBuilder.command(shell, "-c", inputComponent.getText());
Process process = processBuilder.start();
InputStream inputStream = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null)
appendNewText(line);
exitValue = process.waitFor();
Why is it not updating now? I'm suspicious about this:
exitValue = process.waitFor();