dji43466
dji43466

Reputation: 13

Execute 1 batch file after mutiple, simultaneous batch files complete

I have read both the following posts and found that neither of them seem to answer my question How to call one batch file after another, Execute batch file after another batch file completes.

I am attempting to run a series of 6 python scripts through batch files on Windows Server 2012 R2 Standard. I want the first 5 scripts to run simultaneously (Processing.bat), which is currently comprised of five sub bat files (North.bat, West.bat, South.bat, Central.bat, Northeast.bat). Once completed it is then supposed to run one final script that works with the outputs of the first 5 (Merge.bat).

I have tried several combinations of call and start /wait and nothing seems to do it right. Currently my primary bat file looks like:

start /wait Processing.bat
start /wait Merge.bat

Processing.bat looks like:

start North.bat
start South.bat
start NorthEast.bat
start West.bat
start Central.bat

IF %ERRORLEVEL% EQU 0 EXIT 

each sub bat looks like:

start /wait C:\Python27\ArcGIS10.4\python.exe E:\TestScript.py Central 

IF %ERRORLEVEL% EQU 0 EXIT

and finally merge.bat looks like:

start /wait C:\Python27\ArcGIS10.4\python.exe E:\MergeSDE.py

IF %ERRORLEVEL% EQU 0 EXIT

With this setup all 6 scripts will run at once (rather than 5 followed by 1). But the respective command prompt windows will stay open until each script completes (7 windows). The kicker is that if I am to change "start" in Processing.bat to "start /wait" it will run each one after the other (which of the first 5, I don't want), yet with "start /wait" in the primary batch all sub batches run at once.

Upvotes: 1

Views: 1129

Answers (2)

Aacini
Aacini

Reputation: 67216

This is the simplest solution to this problem:

(
start North.bat
start South.bat
start NorthEast.bat
start West.bat
start Central.bat
) | set /P "="

call Merge.bat

Further details at How to wait all batch files to finish before exiting?.

Upvotes: 1

npocmaka
npocmaka

Reputation: 57262

As it is for batch files supposingly you can edit them.

set at the end of the first creation of a flag file:

break>"%temp%\north"

on the second:

break>"%temp%\south"

and so on for the others.

At the beginning of the merge.bat set (if the west.bat is the last executed file):

:wait_again
:: sleep 5 seconds
ping 127.0.0.1 -n 6 > nul
if not exist "%temp%\south" if not exist "%temp%\north" ... (

   goto :wait_again
)

merge.bat should be started again with start command.Also the flag files should be deleted in advance.

Upvotes: 1

Related Questions