To use start, you would need to modify all the subprograms to create an exitcode file on error.
SEE HERE FOR HOW TO HOLD PARENT PROGRAM UNTIL ALL SUBS COMPLETED
@Echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:controller
Call :launcher "a.bat" "b.bat" "c.bat"
pause
EXIT
:launcher
Set count=0
For %%a in (%*) Do (
Set /a count+=1
Set "Prog[!count!]=%%~a"
Start "+++batch+++" "%%~a"
)
:loop
timeout /t 1 >nul
tasklist /fi "windowtitle eq +++batch+++*" |find "cmd.exe" >nul && goto :loop
REM :: Note- This method exits subs on encountering First Error.
For /L %%B IN (1,1,!count!) DO (
FOR %%N IN (!Prog[%%B]!) DO (
IF EXIST "%%~nN_exitcode.txt" (
<"%%~nN_exitcode.txt" (
Set /p exitcode=
Set /p E_P=
Set /p L_N=
)
DEL /Q "%%~nN_exitcode.txt"
IF DEFINED exitcode (
ECHO Errorlevel !exitcode! returned in !E_P! at Line !L_N!
)
) else (
ECHO Sub %%~nN completed succesfully
)
)
)
GOTO :EOF
Child Program Examples:
a.bat
@ECHO OFF
Setlocal EnableDelayedExpansion
CALL Hello|| (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(3)>%~n0_exitcode.txt && EXIT
ECHO HELLO|| (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(4)>%~n0_exitcode.txt && EXIT
exit
b.bat:
@ECHO OFF
Setlocal EnableDelayedExpansion
ECHO Hello|| (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(3)>%~n0_exitcode.txt && EXIT
CALL HELLO|| (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(4)>%~n0_exitcode.txt && EXIT
exit
c.bat
@ECHO OFF
Setlocal EnableDelayedExpansion
ECHO Hello|| (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(3)>%~n0_exitcode.txt && EXIT
ECHO HELLO|| (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(4)>%~n0_exitcode.txt && EXIT
exit
The || (ECHO(!errorlevel!&ECHO(%~nx0&ECHO(4)>%~n0_exitcode.txt && EXIT
creates the file only in the event the preceeding command fails.
ECHO(!errorlevel!
Stores the Errorlevel to the First line of Sub Specific Exitcode file.
ECHO(%~nx0
Stores the filename and extension to the second line.
ECHO(n
Stores the Line Number to the third line. You'll need to adjust this Number to the Line in your Code the command Using this Debugging tool is Positioned at.