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

后端 未结 4 1252
执笔经年
执笔经年 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:28

    Adding to the answer by Aacini. I was also looking for similar task. Objective was to run multiple commands parallel and extract output (stdout & error) of all parallel processes. Then wait for all parallel processes to finish and execute another command. Following is a sample code for BAT file, can be executed in CMD:

    (
    start "" /B cmd /c ping localhost -n 6 ^>nul
    timeout /t 5 /nobreak
    start "" /B /D "C:\users\username\Desktop" cmd /c dir ^> dr.txt ^2^>^&^1
    start "" /B cmd /c ping localhost -n 11 ^>nul
    timeout /t 10 /nobreak
    ) | pause
    Echo waited
    timeout /t 12 /nobreak
    

    All the statements inside () are executed first, wait for them to complete, then last two lines are executed. All commands begining with start are executed simultaneously.

提交回复
热议问题