[comp.lang.c] Setting DOS errorlevel in C

murillo@sigi.Colorado.EDU (Rodrigo Murillo) (03/14/88)

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.
-- 
_______________________________________________________________________________
 Rodrigo Murillo, University of Colorado - Boulder  (303) 761-0410 
 murillo@boulder.colorado.edu | ..{hao|nbires}!boulder!murillo
 ( Machines have less problems.  I'd like to be a machine. -- Andy Worhol )

PLei.ES@Xerox.COM (03/16/88)

Some C compilers allow you to set the errorlevel with the exit statement as you
terminate your program. e.g.: exit(0); for normal exit; exit(x); where x != 0
otherwise. Microsoft C let's you do this.

Hoped that helped.

/Paul

swh@hpsmtc1.HP.COM (Steve Harrold) (03/16/88)

Re: setting errorlevel from C

For Microsoft C use:

int main(....)
...
{
	int  rc ;
	...	
	rc = ... ;
	...
	return rc;
}

Use of exit(rc) would also succeed.

---------------------
Steve Harrold			...hplabs!hpsmtc1!swh
				HPG200/13
				(408) 447-5580
---------------------

john@viper.Lynx.MN.Org (John Stanley) (03/23/88)

In article <11480009@hpsmtc1.HP.COM> swh@hpsmtc1.HP.COM (Steve Harrold) writes:
 >Re: setting errorlevel from C
 >
 >For Microsoft C use:
 >
 >int main(....)
 >...
 >{
 >	int  rc ;
 >	...	
 >	rc = ... ;
 >	...
 >	return rc;
 >}
 >
 >Use of exit(rc) would also succeed.
 >
 >---------------------
 >Steve Harrold			...hplabs!hpsmtc1!swh
 >				HPG200/13
 >				(408) 447-5580
 >---------------------

  If you want your code to be portable, don't use the return-from-main
method.  Any program that you might want to port should use exit(rc)
to return a non-zero exit code.  This is the only method that works
under all C compilers and since exit() is quite offen included in the
initial object-code module it's not likely to make your program much
larger...

--- 
John Stanley (john@viper.UUCP)
Software Consultant - DynaSoft Systems
UUCP: ...{amdahl,ihnp4,rutgers}!meccts!viper!john