0

I have a batch scripts that starts multiple processes (partly other batch files) in background via

start /b /min command1.exe  some params
start /b /min command2.bat  some params
start /b /min command3.exe  some params

at the end of the top level batch script I would like to wait until all processes are completed.

Is there any way to achieve this without implementing special means within the called programs?

vlad_tepesch
  • 6,681
  • 1
  • 38
  • 80
  • 1
    [related](https://stackoverflow.com/questions/49549269/batch-processing-multiple-files-at-the-same-time) – Stephan Apr 07 '20 at 11:42

2 Answers2

0

You can create special batch file that runs another process, waits for it to finish and creates a special file. Then launch desired processes with this script without wait and loop until all files are created. Sample code for inspiration:

Runner.bat:

:: Run, wait and create file; %1 = file name, %2..N - process and params
set FileName=%1
shift
start /b /min /wait %* && (echo OK > %FileName%) || (echo Fail > %FileName%)

Main.bat:

call Runner.bat No1 command1.exe  some params
call Runner.bat No2 command2.bat  some params
...
:Check
... if not exist "No1", "No2", ... (
  timeout /t 5
  goto :Check
)
Fr0sT
  • 2,959
  • 2
  • 25
  • 18
0

One option is to try to start them with WMIC process call create "c:\some.exe","c:\exec_dir" and assign the created PID to variable and checking periodically that the PIDs are existing.

You can try also with :

(
    start ""  /b command1
    start "" /b command2
)|findstr "^"
echo all processes in the brackets block have ended

but if some of the commands is bat file you explicitly'll have to use exit 0 without /b switch.

npocmaka
  • 55,367
  • 18
  • 148
  • 187