| 1. |
Solve : Batch file error level? |
|
Answer» I should be able to work this out myself, but my mind is not working quite right. I have a batch file. I have a command that returns an errorlevel form 0-6. One for each day of the week. I want to 'goto' a tag if the returned error level is 5 or 2. What is an EASYIf "%errorlevel%"=="5" goto foo Not a massive difference in anything, just a little quirk about batch. The old MS-DOS if errorlevel command syntax was preserved in modern Windows command language for backwards compatibilty. In the old version, "if errorlevel N do something" means "if the errorlevel is N or more do something", which is why you have to test for the errorlevels you are interested in, in DESCENDING order. However, the modern version where you test a regular variable called %errorlevel% does not have this restriction, and if you use the arithmetc comparison operators (instead of QUOTES and double equals sign): EQU - equal NEQ - not equal LSS - less than LEQ - less than or equal GTR - greater than GEQ - greater than or equal you don't need any quotes either if %errorlevel% equ 0 if %errorlevel% neq 0 if %errorlevel% gtr 0 etc so you can do without gotos and LABELS too if %errorlevel% equ 5 ( rem the stuff at the :foo LABEL command1 command2 etc ) if %errorlevel% equ 2 ( rem the stuff at the :foobar label command3 command4 etc ) |
|