In Windows batch loop, how to wait for spawned processes to complete before continuing

泄露秘密 提交于 2019-11-29 17:29:40

start /wait isn't "global", it just waits for the started process to finish (maybe... depends on how the application is programmed). What you need (starting several processes in parallel and wait until the last is finished) can be done with a different method: give all your processes a defined title and watch them:

@echo off
setlocal enabledelayedexpansion
for /l %%i in (1,1,10) do (
   start "OneOfMyProcesses" timeout !random:~-1!
)
echo waiting
:loop
timeout 1 >nul
tasklist /v |find "OneOfMyProcesses" >nul && goto :loop
echo all of them are finished

Note: as mentioned above, this may or may not work with your application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!