I have a set of activities that should be run in parallel over a set of sessions.
Each session will run in parallel all tasks and next session will not be run until all tasks in parallel are finished.
run_all_sessions.bat
-> each line should be run, one at a time, and next line should not be launched until the previous one has ended all tasks inside run_batches_1_to_4_in_parallel.bat
:
start /wait run_batches_1_to_4_in_parallel.bat session_id=1
start /wait run_batches_1_to_4_in_parallel.bat session_id=2
start /wait run_batches_1_to_4_in_parallel.bat session_id=3
start /wait run_batches_1_to_4_in_parallel.bat session_id=4
Were run_batches_1_to_4_in_parallel.bat
is a batch file that contains the following information:
start "running_batch_1" batch1.bat %1
start "running_batch_2" batch2.bat %1
start "running_batch_3" batch3.bat %1
start "running_batch_4" batch4.bat %1
exit
The problem I have is that as there is no /wait inside run_batches_1_to_4_in_parallel.bat
and then the next line in run_all_sessions.bat
is run, clogging the machine as the execution of batch*.bat
takes to much resources.
The solution I want to find is to modify run_batches_1_to_4_in_parallel.bat
in the sense that I do not return control to run_all_sessions.bat
until all batch*.bat
in run_batches_1_to_4_in_parallel.bat
have finished and returned their termination code. It should be noted that:
- each batch*.bat returns a lot of stdout and stderr messages
- each
batch*.bat
has a running time that is different and I have to wait until all of them are completed. - No pause can be added in
run_batches_1_to_4_in_parallel.bat
, as the run_all_sessions.bat script should run completely without user interaction. - an asynchronous solution is prefered over a synchronous solution that regularly checks progress, as performance is critical in the machine.
Answer https://stackoverflow.com/a/33586872/4919040 proposes to use set /P "="
but it is expected that all batch*.bat return a lot of output in stdout, so this approach is not feasible.
Answer https://stackoverflow.com/a/33585114/4919040 proposes to check tasklist and filtering but I neither want to filter by process name nor want to be regularly polling and checking whether the processes have finished.
Answer https://stackoverflow.com/a/49051876/4919040 is not useful as the pause command requires user interaction.
I have been suggested to use the following solution for
run_batches_1_to_4_in_parallel.bat
but I fear it does not assure that returns controls after all the batch*.bat
have been finished.
start "running_batch_1" batch1.bat %1
start "running_batch_2" batch2.bat %1
start "running_batch_3" batch3.bat %1
start "running_batch_4" /wait batch4.bat %1
exit