Path: utzoo!mnetor!uunet!husc6!bu-cs!madd From: madd@bu-cs.BU.EDU (Jim Frost) Newsgroups: comp.sys.ibm.pc Subject: Re: Setting DOS errorlevel in C (How?) Message-ID: <20689@bu-cs.BU.EDU> Date: 17 Mar 88 02:40:36 GMT References: <4831@sigi.Colorado.EDU> Reply-To: madd@bu-it.bu.edu (Jim Frost) Followup-To: comp.sys.ibm.pc Distribution: na Organization: Boston University Distributed Systems Group Lines: 41 In article <4831@sigi.Colorado.EDU> murillo@boulder.Colorado.EDU (Rodrigo Murillo) writes: >Does someone out there know how to set the DOS errorlevel number >in C? I want to write a batch file that can branch according to the >value of this number: > > if errorlevel 1 echo Big... > if errorlevel 2 echo Bigger... > if errorlevel 3 echo Biggest. > >Please send code fragments if possible. You're going to get a million of these, but I thought I'd add to your mail. The answer is so obvious that it's often missed. DOS ERRORLEVEL is nothing but a check of the return code for a program (as specified when function 4CH Terminate a program (EXIT) is called). The IBM Disk Operating System Technical Manual says: Purpose: Terminates the current process and transfers control to the invoking process. On Entry Register Contents AH 4CH AL Return code On Return Register Contents NONE Remarks: In addition, a return code can be sent. The return code can be interrogated by the batch subcommands IF and ERRORLEVEL and by the wait function call 4DH. All files opened by the process are closed. In C on the PC, the return code is an optional argument to the exit() command. Thus, exit(2) will return ERRORLEVEL 2. Happy hacking, jim frost madd@bu-it.bu.edu