Command: errorlevel (exitcode)
Errorlevel is NO existing command but part of the IF command.
It is also called EXITCODE. As it is often in use there is an
own "command" here to show where and how it can be used.
Syntax:
SEE: IF command
Options:
SEE: IF command
Comments:
Sometimes ERRORLEVELS are not documented in programs. With a trick
you can try to find out if the program has some:
Try to run a program in a way where you know that it cannot function,
e.g.:
"dir --help" and then "echo %errorlevel" (return= 2) OR:
"chkdsk 2: /h" and then: "echo %errorlevel%" (return=2) OR:
"mode con cp prepare ((437) C:\FREEDOS\CPI\ega22.cpx" (return=255) OR:
"mode con cp prepare ((437) C:\FREEDOS\CPI\ega22.cpx)" (return=101)
Examples:
Example 1:
path C:\FREEDOS;C:\FREEDOS\BIN
cls
@ECHO. Please choose a keyboard driver:
@ECHO. A = US = United States
@ECHO. B = GR = German
@ECHO. C = SP = Spanish
@ECHO. D = FR = French
@ECHO. E = TR = Turkish Q layout
@ECHO. F = TRF = Turkish F layout
@choice /B /N /C:ABCDEF "Please choose your driver: "
cls
if errorlevel 7 goto :GO_ON
if errorlevel 6 goto :KEYB_F
if errorlevel 5 goto :KEYB_E
if errorlevel 4 goto :KEYB_D
if errorlevel 3 goto :KEYB_C
if errorlevel 2 goto :KEYB_B
if errorlevel 1 goto :KEYB_A
:KEYB_A
lh mkeyb.exe US
goto :GO_ON
:KEYB_B
lh mkeyb.exe GR
goto :GO_ON
:KEYB_C
lh mkeyb.exe SP
goto :GO_ON
:KEYB_D
lh mkeyb.exe FR
goto :GO_ON
:KEYB_E
lh mkeyb.exe TR
goto :GO_ON
:KEYB_F
lh mkeyb.exe TRF
goto :GO_ON
:GO_ON
cls
Example 2:
IN A BATCH FILE:
C:\FREEDOS\BIN\defrag C:
if errorlevel 9 echo out of memory
if errorlevel 8 echo memory error
if errorlevel 7 echo FAT allocation error
if errorlevel 6 echo write error
if errorlevel 5 echo read error
if errorlevel 4 echo general error
if errorlevel 3 echo aborted by user
if errorlevel 2 echo disk too full to defrag
if errorlevel 1 echo internal error
if errorlevel 0 echo success
pause
See also:
FreeDOS commands that support IF / ERRORLEVEL:
assign attrib chkdsk choice ctmouse
defrag deltree diskcomp fc fdisk
find format goto join keyb
mode replace shsucdx subst swsubst
tdsk xcopy pcisleep shsufdrv touch
xgrep
Copyright © 2022 by W. Spiegl.
This file is derived from the FreeDOS Spec Command HOWTO.
See the file H2Cpying for copying conditions.