I seem to always forget how to set an error leve in side a batch file, but [WayBack] Errorlevel – Windows CMD – SS64.com tells how:
- When ending a [WayBack] subroutine, you can use
EXIT /b N
to set a specificERRORLEVEL N
. - You can make a [WayBack] batch file return a non-zero exit code by using the [WayBack] EXIT command.
Exit 0
Exit /B 5
To force an
ERRORLEVEL
of 1 to be set without exiting, run a small but invalid command like [WayBack]COLOR 00
There is a key difference between the way .CMD and .BAT batch files set errorlevels:
An old .BAT batch script running the ‘new’ internal commands:
APPEND
,ASSOC
,PATH
,PROMPT
,FTYPE
andSET
will only setERRORLEVEL
if an error occurs. So if you have two commands in the batch script and the first fails, theERRORLEVEL
will remain set even after the second command succeeds.This can make debugging a problem
BAT
script more difficult, aCMD
batch script is more consistent and will setERRORLEVEL
after every command that you run [[archive.is]source].
It looks like I already used a bare EXIT /B
without explaining it in Source: stop/start IIS.
Further reading, including the difference between subroutines, blocks and batch files:
- [WayBack] Set errorlevel in Windows batch file – Stack Overflow
- [WayBack] Batch Files – Error Handling – Stack Overflow
Finally saving Google Groups messages in the way back machine:
- Convert the URL
- Save the latter in archive.is
–jeroen