[ACCEPTED]-Executing a Command from Java and Waiting for the Command to Finish-execute

Accepted answer
Score: 27

I manged to find the answer elsewhere. To 2 keep the initial process open until the 1 batch file finished all you need is "/wait"

Process p = Runtime.getRuntime().exec("cmd /C start /wait filepath.bat");
int exitVal = p.waitFor();
Score: 3

calling "cmd /c start" causes cmd to fire 2 off another instance and exit immediately. Try 1 taking out the "start" command.

Score: 3

The answer given is correct. I added that 2 the window opened by the code needs to be 1 closed manually.

Process p = Runtime.getRuntime().exec("cmd /C start /wait filepath.bat");
int exitVal = p.waitFor();

More Related questions