You are currently offline, waiting for your internet to reconnect

Setting the MS-DOS Errorlevel in a Program

This article was previously published under Q57658
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
This article explains how you can set the errorlevel of a program for useby the MS-DOS batch file IF ERRORLEVEL command.
If you are writing a program that is going to be invoked from within anMS-DOS batch file that uses the IF ERRORLEVEL command, you can useInterrupt 21H Function 4CH, "Terminate Process with Return Code" to set theerrorlevel in your program. This function terminates the program andreturns the errorlevel to the parent process, which in this case isCOMMAND.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 beany value in the range 0 to 255 (0 to FF, hexadecimal).
"Microsoft MS-DOS User's Guide and Reference" for versions 4.x.

"Microsoft MS-DOS Programmer's Reference," version 4.0, Chapter 1,pages 237-238.

"MS-DOS Encyclopedia," Ray Duncan, Microsoft Press, Article 4, pages115-117, and Section V, pages 1375-1376.

"Advanced MS-DOS Programming," Ray Duncan, Microsoft Press, SectionII, pages 443-444.

"The New Peter Norton Programmer's Guide to the IBM PC & PS/2," PeterNorton and Richard Wilton, Microsoft Press, Chapter 17, page 377.
6.22 3.2 3.20 3.21 3.3 3.30 3.3a 3.30a 4.00 4.00a 4.01 4.01a 5.00 5.00a 6.00 6.20 error level

Article ID: 57658 - Last Review: 05/12/2003 21:01:52 - Revision: 2.0

  • 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
  • KB57658