Question: I have a series of bat files that I want to run in parallel, for example:

```
start program1_1.bat
start program1_2.bat
start program1_3.bat
wait until program1 finished then
start program2_1.bat
start program2_2.bat
start program2_3.bat
wait until program2 finished then
...

```

So far, what I've tried is this [function](https://stackoverflow.com/questions/41584281/how-to-run-three-batch-files-in-parallel-and-run-another-three-batch-files-after):

```
:waitForFinish
set counter=0
for /f %%i in ('tasklist /NH /FI "Imagename eq cmd.exe') do set /a counter=counter+1
if counter GTR 2 Goto waitForFinish

```

But it just launched the first 3 bat files and stop... How can I solve this problem?
Thanks,

EDIT: This is the content of `program1_i.bat` file:

```
program1.exe input_i.txt

```

It will run program1.exe for each input file. The same for `program2_i.bat`.

Answer: 
Ok, here is what worked for me:

```
@echo off
setlocal enableextensions enabledelayedexpansion
call :InitDos
start program1_1.bat
start program1_2.bat
start program1_3.bat
call :waitForFinish
start program2_1.bat
start program2_2.bat
start program2_3.bat
call :waitForFinish
Goto:eof
: waitForFinish
set /a counter=0
for /f %%i in ('tasklist /NH /FI "Imagename eq cmd.exe"') do (
    set /a counter+=1
)
if !counter! GTR !init_count! Goto waitForFinish
goto :eof
: InitDos
set /a init_count=0
for /f %%i in ('tasklist /NH /FI "Imagename eq cmd.exe"') do (
    set /a init_count+=1
)
goto :eof

```
Try `/WAIT` switch on `start` command. I guess if you wrap bats into script called with wait switch, it could work.