开发者

Wait for executable to finish running

开发者 https://www.devze.com 2023-02-17 21:57 出处:网络
Can you run two executables in a batch file and wait for the firs开发者_高级运维t process to end before starting the next?Use start /wait:

Can you run two executables in a batch file and wait for the firs开发者_高级运维t process to end before starting the next?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消