Even if you hate labels, refusing to use them limits your options here. I can't think of an easy way to do this within a single file. If you don't hate the idea of using two batch files, you can do something like this. Running a.cmd
will CALL b.cmd
and perform ERRORLEVEL
check based on any EXIT /B
in b.cmd
.
a.cmd:
REM a.cmd
@ECHO OFF
SET CHECKVAR=10
CALL b.cmd
IF ERRORLEVEL %CHECKVAR% (
REM go here when exit from b.cmd met condition
ECHO "B was %CHECKVAR%"
) ELSE (
REM go here when exit from b.cmd did not meet condition
ECHO "B was not %CHECKVAR%"
)
b.cmd
REM b.cmd
@ECHO OFF
FOR /L %%A IN (0,1,3) DO (
ECHO "A: %%A"
FOR /L %%B IN (0,1,100) DO (
ECHO "B: %%B"
REM Do what ever conditional check you like here.
REM Just need to return some ERRORLEVEL to a.cmd.
IF %%B==%CHECKVAR% (
EXIT /B %CHECKVAR%
)
)
)
break
is for turning on/off the ctrl+c sequence.