Hi.
I've got a windows batch file, with a few sub-routines in it something like this:
call :a
goto :eof
:a
call :b
goto :eof
:b
:: How do I directly exit here from here?
goto :eof
I'm running this in a cmd window on Vista.
If I detect an error somewhere in the batch file, I want it to exit with a non-zero errorlevel. Is there anything I can write in the routine :b that will cause the batch file to terminate like this.
- I've tried 'exit', which closes the entire cmd window. That's not what I want.
- I've tried 'exit /B 1'. That returns to the previous routine. To use this scheme after every 'call' I'd have to carefully write 'if errorlevel 1 exit /B 1' after every single 'call' to pass the error back up the call stack. I'd prefer not to have to write this line after every call.
This article was interesting, but non of the alternatives behave in the way I want. http://www.computerhope.com/exithlp.htm
Is there another way?
Thanks.