Setting the MS-DOS Errorlevel in a Program (57658)



The information in this article applies to:
    Microsoft MS-DOS operating system 3.1
    Microsoft MS-DOS operating system 3.2
    Microsoft MS-DOS operating system 3.21
    Microsoft MS-DOS operating system 3.3
    Microsoft MS-DOS operating system 3.3a
    Microsoft MS-DOS operating system 4.0
    Microsoft MS-DOS operating system 4.01
    Microsoft MS-DOS operating system 5.0
    Microsoft MS-DOS operating system 6.0
    Microsoft MS-DOS operating system 6.2
    Microsoft MS-DOS operating system 6.21
    Microsoft MS-DOS operating system 6.22

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, "Terminate Process with Return Code" 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).

REFERENCES

"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, pages 115-117, and Section V, pages 1375-1376.

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

"The New Peter Norton Programmer's Guide to the IBM PC & PS/2," Peter Norton and Richard Wilton, Microsoft Press, Chapter 17, page 377.

Modification Type: Major Last Reviewed: 5/12/2003
Keywords: KB57658