Microsoft KB Archive/57658

= Setting the MS-DOS Errorlevel in a Program =

Article ID: 57658

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft MS-DOS 3.1
 * Microsoft MS-DOS 3.2 Standard Edition
 * Microsoft MS-DOS 3.21 Standard Edition
 * Microsoft MS-DOS 3.3 Standard Edition
 * Microsoft MS-DOS 3.3a
 * Microsoft MS-DOS 4.0 Standard Edition
 * Microsoft MS-DOS 4.01 Standard Edition
 * Microsoft MS-DOS 5.0 Standard Edition
 * Microsoft MS-DOS 6.0 Standard Edition
 * Microsoft MS-DOS 6.2 Standard Edition
 * Microsoft MS-DOS 6.21 Standard Edition
 * Microsoft MS-DOS 6.22 Standard Edition

-



This article was previously published under Q57658



SUMMARY
This article explains how you can set the errorlevel of a program for use by the MS-DOS batch file IF ERRORLEVEL command.



MORE INFORMATION
If you are writing a program that is going to be invoked from within an MS-DOS batch file that uses the IF ERRORLEVEL command, you can use Interrupt 21H Function 4CH, &quot;Terminate Process with Return Code&quot; to set the errorlevel in your program. This function terminates the program and returns the errorlevel to the parent process, which in this case is COMMAND.COM running the batch file.

The parameters for Interrupt 21H, Function 4CH are AH = 4CH, AL = errorlevel, followed by a call to Interrupt 21H. The errorlevel can be any value in the range 0 to 255 (0 to FF, hexadecimal).

