Execute multiple batch files concurrently and monitor if their process is completed

后端 未结 4 1254
执笔经年
执笔经年 2020-11-29 12:55

I have a main batch file which calls multiple batch files. I want to be able to execute all these batch files at the same time. Once they are all done, I have further proces

4条回答
  •  情书的邮戳
    2020-11-29 13:29

    This is the simplest and most efficient way to solve this problem:

    (
    start first.bat
    start second.bat
    start third.bat
    ) | pause
    
    echo done!
    

    In this method the waiting state in the main file is event driven, so it does not consume any CPU time. The pause command would terminate when anyone of the commands in the ( block ) outputs a character, but start commands don't show any output in this cmd.exe. In this way, pause keeps waiting for a char until all processes started by start commands ends. At that point the pipe line associated to the ( block ) is closed, so the pause Stdin is closed and the command is terminated by cmd.exe.

提交回复
热议问题