ProcessBuilder and Process.waitFor(), how long does it wait?

Additionally, If there are outputs in the "commands". you should read the standard output and standard error output by stream(process.getErrorStream()) and process.getInputStream()).If not and output or error output be full, the waitfor() would be hanged.


It will wait till the process is finished. Workaround:

1 Use isAlive()

2 Use waitFor(long timeout, TimeUnit unit) (Only 1.8)


Your current execution thread will be blocked on process.waitFor() until process is terminated (i.e. execution finished). Source here

Also note that if process is already terminated : waitFor() will not be blocked. I don't know if the code you put in your question is exactly what you run... but you must be careful and re-create a new instance of Process for every execution of your script (i.e. not just calling start multiple times on the same Process: it won't work after first execution)