cmd - run a batch file after all other concurrent batch files finish
I have a simple batch file which calls other batch files, it looks like this:
start /b run_part1.bat
start /b run_part2.bat
start /b run_part3.bat
start /b run_part4.bat
run_last.bat // fires immediately, how to make this line wait until above finishes?
With the /b the first 4 files will run concurrently. All will finish within 1.5 hours.
I need another script to do some cleaning up after all the four files finish. However the run_last.bat will not wait for the first 4 files, it is called at the same time with the first 4.
Is there a way to achieve it?
Thank you.
Stop using the antiquated command prompt and use Powershell. You can use the ThreadJob module, as described in this excellent answer on SO:
$commands = { ./run_part1.bat },
{ ./run_part2.bat },
{ ./run_part3.bat },
{ ./run_part4.bat }
$jobs = $commands | Foreach-Object { Start-ThreadJob $_ }
$jobs | Receive-Job -Wait -AutoRemoveJob
./run_last.bat