Wait for multiple applications run asynchronously from batch file to finish

后端 未结 6 1453
再見小時候
再見小時候 2020-12-13 21:15

There is a simple Windows batch file that runs multiple instances of application:

start app.exe param1
start app.exe param2

Is there a way

6条回答
  •  青春惊慌失措
    2020-12-13 21:52

    Adapting on @dbenham answer, here's how i made it to work inside a for and for unlimited number of processes:

    setlocal enabledelayedexpansion
    for %%a in (*.*) do start "" 9>"%temp%/wait!random!.lock" /b /low "myprogram.exe" -program_parameters
    
    :wait
    ping /n 2 ::1 > nul
    echo waiting processes to finish...
    2>nul del "%temp%\wait*.lock" > nul
    if exist "%temp%\wait*.lock" goto :wait
    
    ... more commands ...
    

    Here %random% don't work, cause it's expanded when for is called, therefore making all numbers the same. So I enabledelayedexpansion and use !random!.

    On the loop I try to delete all files. 2>nul will make sure any error won't show on screen. It will only go through when all can be deleted (if exist).

提交回复
热议问题