I have a Java GUI application that runs some Python scripts and Linux applications. The code looks basically like this (can't post actual source due to policy):
private void runScript(ArrayList<String> aList)
{
tA.append("Starting Process...");
ProcessBuilder pb = new ProcessBuilder(aList);
pb.redirectErrorStream(true);
pb.redirectOutput();
Process p = pb.start();
tA.append("Process complete.");
}
where tA is a JTextArea in the main GUI and runScript is a method of the GUI class. The issue I'm having is that tA.append("Starting Process...");
doesn't seem to run before pb.start();
- nothing displays in the JTextArea until the Process is done executing. I've tried throwing a Thread.sleep(100)
just after the first tA.append()
but that doesn't seem to work. I have also tried this:
...
{
syncrhonized(this)
{
tA.append("Starting Process...");
<rest of code>
}
}
but it still doesn't seem to populate the JTextArea before the process runs. Is there a way to enforce the sequential execution of these method calls?