Blocking vs. Non-Blocking Calls
suggest changeIn general when making a call to the command line, the program will send the command and then continue its execution.
You may instead want to wait until the called program finishes. For example, it writes a file that your program then reads. If the child fills its stdout or stderr buffer and nothing reads those streams, waitFor() can wait forever.
This can easily be done by calling the waitFor() method from the returned Process instance.
Usage example:
//code setting up the commands omitted for brevity...
ProcessBuilder pb = new ProcessBuilder(cmds);
try {
Process p = pb.start();
p.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
//more lines of code here...
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents