Path: utzoo!mnetor!uunet!husc6!mailrus!nrl-cmf!ames!hao!boulder!murillo From: murillo@sigi.Colorado.EDU (Rodrigo Murillo) Newsgroups: comp.sys.ibm.pc Subject: More on setting DOS errorlevel Message-ID: <4835@sigi.Colorado.EDU> Date: 14 Mar 88 21:54:45 GMT Reply-To: murillo@boulder.Colorado.EDU (Rodrigo Murillo) Followup-To: comp.sys.ibm.pc Distribution: na Organization: University of Colorado, Boulder Lines: 61 I posted an article asking how to set DOS errorlevel from a C program. Someone suggested exit(errorlevel). But wait... The following code shows that exit(errorlevel) works. The problem is that if errorlevel is set with an exit(5) for example, all if tests for values <= to 5 are tested as true. This is some sample output showing the results of passing 5 parameters to the batch file, which calls ERRLEVEL which does an exit(5): F:\>errtest 1 2 3 4 5 F:\>echo off exit(5); FIVE! FOUR! THREE! TWO! ONE! ZERO! F:\> If anybody can tell why this is the way it is I would love to hear it. Why would (errorlevel 0) test true if the exit is exit(5)??!! ==>errlevel.c /* exit(n) with the number of paramters passed to it */ main(argc, argv) int argc; char *argv[]; { printf("\nexit(%d);\n",argc-1); exit(argc-1); } /* end of program */ ==>errtest.bat echo off errlevel %1 %2 %3 %4 %5 %6 %7 %8 if errorlevel 8 echo EIGHT! if errorlevel 7 echo SEVEN! if errorlevel 6 echo SIX! if errorlevel 5 echo FIVE! if errorlevel 4 echo FOUR! if errorlevel 3 echo THREE! if errorlevel 2 echo TWO! if errorlevel 1 echo ONE! if errorlevel 0 echo ZERO! -- _______________________________________________________________________________ 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 )