How it works: ERRLEV is a small "shell" which invokes your program. When your program exits, it returns control (and its ErrorLevel) to ERRLEV, which displays the ErrorLevel before exiting to the command shell which invoked it. ERRLEV also passes the ErrorLevel on to its command shell.
ERRLEV filename paramswhere filename is the name of the executable program. The extension .EXE or .COM is optional. ERRLEV will find it anywhere on your path, or you may explicitly specify a path if you prefer.
Note: ERRLEV only works with executable binary programs (.EXE, .COM). It does not support internal commands, batch (.BAT) files, or DOSKEY macros.
After introducing itself, ERRLEV gives the full path name of the executable file it found, and then executes it with the parameters you specified. When your executable program teminates; ERRLEV displays two lines of status. The first line tells whether the program terminated nomally, by Ctrl-Break, by a device error, or stayed resident. The second displays the errorlevel returned, as a decimal integer. ERRLEV then itself terminates, passing on to its invoking command shell the same error level with which your program terminated.
All output from ERRLEV itself is directed to the "Standard Error" device. This facilitates separation of the output of ERRLEV from the output of the program it is supervising. For example, if MYPROG generates a lot of output to the "Standard Output" device, that output can be redirected to a file, as
ERRLEV MYPROG >OUTFILE.DAT
SETERR nwhere n is an integer in the range 0..255. Hexadecimal number may be indicated by preceding with a dollar sign $. For examples,
SETERR 1 SETERR 255 SETERR $FFApplication examples:
BAT1.BAT BAT2.BAT -------- -------- ... ... SETERR 0 call BAT1 goto end if not errorlevel 1 goto end ... echo BAT1 returned ErrorLevel 1 SETERR 1 :end :end
seterr 1 format A: if not errorlevel 1 goto end echo Could not find FORMAT.COM :end