0

Say I have 5 batch files that need to run simultaneously to save time; these 5 batch files are all currently called from the same MakeAll batch file with:

START /D PATH "Window Name" BATCH_FILE ARGUMENTS

I then have 2 other batch files that need to run when all 5 of the previous group (MakeAll) are done running; these 2 batch files are called 4 times with different arguments from the same AssembleAll batch file with the same command above.

Ideally I'd like to create another batch file called DoAll that first runs MakeAll and waits for the 5 associated processes to finish and then calls AssembleAll.

Code

DoAll.bat:

START /D Folder9 "Window9" MakeAll.bat
:: Wait for the above to finish all 5 windows
START /D Folder10 "Window510" AssembleAll.bat

MakeAll.bat:

START /D Folder1 "Window1" prog1.bat
START /D Folder2 "Window2" prog2.bat
START /D Folder3 "Window3" prog3.bat
START /D Folder4 "Window4" prog4.bat
START /D Folder5 "Window5" prog5.bat

AssembleAll.bat:

START /D Folder5 "Window5" prog5.bat
START /D Folder6 "Window6" prog6.bat
START /D Folder7 "Window7" prog7.bat
START /D Folder8 "Window8" prog8.bat

All progX.bat files contain:

ECHO Running
gunslingor
  • 1,358
  • 12
  • 34
  • 1
    After being a member here for five years, you should be aware that StackOverflow is a site where you ask a specific question based upon a posted [mcve] of your code and explanation of how it fails to work as written and intended. You have not asked a question, only provided a 'to do' list, and you need to [edit your question](https://stackoverflow.com/posts/56378357/edit) to bring it on-topic, if you want specific help with something. – Compo May 30 '19 at 12:37
  • Well you've now expanded upon your 'to do' list, but still not asked a specific question. Please note that "can you write my script for me" is not an acceptable question, but currently appears to be exactly what you're expecting. Also if `ECHO Running` was really the content of your `progX.bat` files, there'd be no need to set the working directories of each either. – Compo May 30 '19 at 14:22
  • Never requested that someone write anything for me, just trying to understand a way to effectively do parallel processing with batch, which requires a synchronization of start/end events... ECHO Running is obviously a placeholder, you don't want to see my 4 page batch files and I couldn't show them to you anyway. I'm sorry the question was a little poorly worded, "wait for all batch files to finish" does make more sense within the batch context so thanks for clarifying, I'm not a batch programmer so I was being to general I suppose. – gunslingor May 30 '19 at 17:57

1 Answers1

2

In despite of the question title, I don't think you want to "synchronize" Batch files, but to "wait for all batch files to finish before continue". I completed a simple search on this site with previous phrase and found a question named: How to wait all batch files to finish before exiting? that I think is the solution you are looking for:

echo MakeAll.bat starts
(
START /D Folder1 "Window1" prog1.bat
START /D Folder2 "Window2" prog2.bat
START /D Folder3 "Window3" prog3.bat
START /D Folder4 "Window4" prog4.bat
START /D Folder5 "Window5" prog5.bat
) | pause
echo MakeAll.bat ends

echo AssembleAll.bat starts
(
START /D Folder5 "Window5" prog5.bat
START /D Folder6 "Window6" prog6.bat
START /D Folder7 "Window7" prog7.bat
START /D Folder8 "Window8" prog8.bat
) | pause
echo AssembleAll.bat ends

For an explanation on the method used, see the linked answer...

Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Thank you, I was obviously searching the wrong terms. – gunslingor May 30 '19 at 17:58
  • Is it possible to do a FOR lopp inside the clause instead of several START rows? I tried with no success. – Johan Danforth Aug 09 '22 at 11:18
  • @JohanDanforth: Yes, of course. Just use something like `( for %%a in (*.bat) do start "Title" "%%a" ) | pause` Pay attention to parentheses that enclose _the whole FOR_ – Aacini Aug 09 '22 at 19:35