tl;dr : I wanna execute multiple commands in parallel (we're in 2013 after all) YET (that's where it become tricky) retrieve the exit error code of the processes.
From the following script : https://stackoverflow.com/a/11715437/3069988
I managed to implement this solution into my own batch file, my own version looked more like this :
- - - 8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
set /a "cmin=0"
set /a "cmax=%NUMBER_OF_PROCESSORS%-(1-%cmin%)"
set "lock=.\lock"
del "%lock%*" /f /q 1>nul 2>nul
set "lock=%lock%.%fdate%_%ftime%.cpu"
for %%i in (%vlst%) do (
==========
rem Start the process on the first unlocked CPU
set /a "pcnt=0"
for /l %%b in (%cmin%,1,!mcpu!) do (
if !pcnt! equ 0 (
if not exist "%lock%.%%b" (
set /a "pcnt+=1"
call:tohex %%b
rem The 'affinity' parameter BITFIELD select the CPU
start "CPU%%b" /b /affinity !hex! /low cmd /c 9>"%lock%.%%b" !vcmd!
)
)
) 2>nul
:wait
rem Wait for a CPU to get unlocked
set /a "pcnt=0-1"
for /l %%b in (%cmin%,1,!mcpu!) do (
if exist "%lock%.%%b" (
del "%lock%.%%b" /q 1>nul 2>nul
if exist "%lock%.%%b" (
set /a "pcnt+=1"
)
)
) 2>nul
rem If all CPU are locked, wait again
if !pcnt! geq !mcpu! (
ping 1.1.1.1 /n 1 1>nul 2>nul
goto wait
)
==========
)
:final
rem Wait for all remaining CPU to be unlocked
for /l %%b in (%cmin%,1,!mcpu!) do (
if exist "%lock%.%%b" (
ping 1.1.1.1 /n 1 1>nul 2>nul
del "%lock%.%%b" /q 1>nul 2>nul
goto final
)
) 2>nul
rem del "%lock%*" /f /q 1>nul 2>nul
goto :eof
- - - 8< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
However I had lock issues.
Well, now that my script works (more or less) with the OP's solution, I have 4 processes running concurrently, and when one exit with an error code above 0, I'd like to catch that and exit my own script reflecting this error (not necessarely the same error code, a simple exit /b 1 should suffise)
Thanks for the feedback...
PS : created another thread because unable to ask OP as replying request 50+ reputations :) So let the topic flood begin :)