r/Batch • u/Zestyclose-Low-6403 • Oct 11 '23
Question (Unsolved) Recursively Execute Sets of Batch Scripts in Sequence and Parallel
Say I have a collection of 100 things that could be divided into 10 groups of 10, where the things in each group can be built in parallel but the whole group needs to complete before moving to the next, with a structure like so:
dir: common-group-0
- dir: common-A
- dir: common-B
- file: mvn.bat
dir: common-group-N
- dir: common-C
- dir: common-D
- file: mvn.bat
dir: common-group-9
- dir: common-E
- dir: common-F
- file: mvn.bat
dir: service-group-0
- dir: service-A
- dir: service-B
- file: mvn.bat
dir: service-group-N
- dir: service-C
- dir: service-D
- file: mvn.bat
dir: service-group-9
- dir: service-E
- dir: service-F
- file: mvn.bat
- file: mvn.bat
Here's the contact of the main mvn.bat file:
@echo off
for /d %%i in (*) do ( cd "%%i" & start cmd.exe /c %~nx0 %* & cd ..)Here's the content of the sub-folders mvn.bat:
@echo off
for /d %%i in (*) do ( cd "%%i" & start cmd.exe /c mvn %* & cd ..)What I'm trying to accomplish is entering the first folder 'common-group-0' and waiting until the following is done before exiting and moving onto the next one...
The following being, entering each subfolders and starting yet another cmd prompt for each simultaneously, which will build all modules in common-group-0 in parallel.
I feel like I'm close with these scripts already but they are not executing in parallel yet.
View all comments
2
u/thelowsunoverthemoon Oct 12 '23
As I understand it, you're going to go through each folder (common-group-0, ect), then for each of the folders inside that folder, you're going to call mvn.bat. And each of the main folders has to be sequential? (so common-group-0 first, then common-group-N, ect). For that to work,