Wait for process to finish before proceeding in Java

Call Process#waitFor(). Its Javadoc says:

Causes the current thread to wait, if necessary, until the process represented by this Process object has terminated.

Bonus: you get the exit value of the subprocess. So you can check whether it exited successfully with code 0, or whether an error occured (non-zero exit code).

Leave a Comment