I'm trying to write a batch file that, for a set of numbers (1 to 10), starts an executable sequentially. The numbers from the set of numbers are being passed to a file for the executable to run in batch mode. However, because the executable hogs resources, I want only 5 of these executables running at a time (there will be a total of 1500 executable runs in total). I've jimmy-rigged some script to monitor the tasklist and to not continue starting the executable while 5 of the executable are currently running. Once the number of tasks goes back down to 4, the next executable will be started.
Simplified minimum working example (I'm obviously not running notepad):
FOR %%g IN (1 2 3 4 5 6 7 8 9) DO (
:loop
tasklist | find /I /C "OpenSees.exe" >process.txt
FOR /F "tokens=*" %%a IN (process.txt) DO (
IF "%%a" EQU "5" (goto :loop)
)
start notepad.exe
PAUSE
)
What happens here is that once %%a does equal 5, goto is invoked, and the loop works fine and doesn't start more executables. However, once one "notepad" is closed, the waiting loop is broken (as intended), but the initial FOR loop is also broken (%%g is no longer a defined variable) and the script ends without %%g passing 5 to 6 7 8 and 9. Echo %%g gives back echo %g while the waiting loop is looping through.
What am I doing wrong here?
Thank you in advance.