Can you run two executables in a batch file and wait for the first process to end before starting the next?
Use /WAIT to Wait for a Command to Finish Execution When we start a program in a Batch file using the START command, we can wait until the program is finished by adding /wait to the START command.
You can use timeout command to wait for command prompt or batch script for the specified amount of time. The time is defined in Seconds. The above commands will break the timeout process on pressing any key. You can use /NOBREAK ignore key presses and wait for the specified time.
You can insert the pause command before a section of the batch file that you might not want to process. When pause suspends processing of the batch program, you can press CTRL+C and then press Y to stop the batch program.
Execution of a batch script can also be paused by pressing CTRL-S (or the Pause|Break key) on the keyboard, this also works for pausing a single command such as a long DIR /s listing.
Use start /wait:
:NOTEPAD
start /wait notepad.exe
IF %ERRORLEVEL% == 0 goto NEXTITEM1
else goto QUIT
:NEXTITEM1
start /wait mplayer.exe
IF %ERRORLEVEL% == 0 goto NEXTITEM2
else goto QUIT
:NEXTITEM2
start /wait explorer.exe
IF %ERRORLEVEL% == 0 goto NEXTITEM3
else goto QUIT
:NEXTITEM3
REM You get the idea...
:QUIT
exit
In addition, use NT CMD rather than BAT (myscript.cmd).
In response to the comments, brackets removed from the above script around %ERRORLEVEL%. The following seems to behave as expected:
:NOTEPAD
start /wait notepad.exe || goto QUIT
:NEXTITEM1
start /wait mplayer2.exe || goto QUIT
:NEXTITEM2
REM You get the idea...
:QUIT
exit
The statement after the double-pipe only executes if what is before it fails.
one shorter way:
notepad.exe|more
even this can be used:
notepad|rem
though eventually with more
you'll able to catch some output if there's any.And this is the reason it works - the piped command waits for input until the .exe is finished.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With