Wait for process to finish before proceeding in Java -
essentially, i'm making small program that's going install software, , run basic commands afterwards prep program. however, happening program starts install, , moves on following lines (registration, updates, etc). of course, can't happen until it's installed, i'd find way of waiting on first process before running second. example,
main.say("installing..."); process p1 = runtime.getruntime().exec(dir + "setup.exe /silent"); //wait here, need finish installing first! main.say("registering..."); process p2 = runtime.getruntime().exec(installdir + "program.exe /register aaaa-bbbb-cccc"); main.say("updating..."); process p4 = runtime.getruntime().exec(installdir + "program.exe /update -silent");
call process#waitfor()
. javadoc says:
causes current thread wait, if necessary, until process represented
process
object has terminated.
bonus: exit value of subprocess. can check whether exited code 0
, or whether error occured (non-zero exit code).
Comments
Post a Comment