You are not logged in.
Pages: 1
Hi,
Its my understanding that issuing an "exit /b" from anywhere within the script will cause execution to stop. However, I'm issuing an "exit /b" from within an internal subroutine ":s_sub1" and the behavior that I'm experiencing is that the subroutine is being exited but then processing continues with the call to the next subroutine, ":s_sub2". Example:
::MAIN
call :s_sub1
call :s_sub2
:: END MAIN
:s_sub1
IF [condition] exit /b
GOTO :eof
What am I misunderstanding?
Thanks,
Scott
Offline
I would try to do exit 0 or exit -1 instead of /b, not really sure what's the difference though.
I always try to help
Sometimes I don't know how
Offline
I hadn't explored this feature(?) myself, but I'm presuming that what happens when you issue a "call :label" command, effectively another instance of CMD is launched, which processes the procedure. Thus when you "exit /b" from a called procedure you are terminating this child CMD instance, rather than the parent.
This actually looks quite handy, because you can exit a procedure with a trapable errorlevel set. See this code sample (and your own experience!)
@echo off
call :this
echo %errorlevel%
call :that
echo %errorlevel%
pause
goto :EOF
:this
echo %~0
exit /b 1
goto :EOF
:that
echo %~0
exit /b 2
goto :EOF
To make it do what you want to do, you'd either need to lose the "/b" switch (resulting in a quick and dirty end to the script), or check the exit condition after the "call :label" line and issue an "exit", "exit /b" or "goto :EOF" at that point. Does that make sense? I know what I mean
~bxm
cmd | *sh | ruby | chef
Offline
Pages: 1