Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cca!mirror!jvc From: jvc@mirror.UUCP Newsgroups: comp.lang.c Subject: Re: 1 Turbo C question (used to be 2) Message-ID: <236100002@mirror> Date: Tue, 1-Sep-87 08:36:00 EDT Article-I.D.: mirror.236100002 Posted: Tue Sep 1 08:36:00 1987 Date-Received: Sat, 5-Sep-87 03:32:59 EDT References: <9061@brl-adm.ARPA> Lines: 70 Nf-ID: #R:brl-adm.ARPA:-906100:mirror:236100002:000:2106 Nf-From: mirror.UUCP!jvc Sep 1 08:36:00 1987 /* Written 7:35 pm Aug 30, 1987 by toma@killer.UUCP in comp.lang.c */ >You have something in dos called errorlevel that will give you the value >you exit()ed with. This could be used in a batch file like this... > >. REM RUN MAIN PROGRAM >. MAINPGM >. IF ERRORLEVEL 0 GOTO GOOD >. IF ERRORLEVEL 1 GOTO BAD >. IF ERRORLEVEL 2 GOTO HAWAII >. :GOOD >. ECHO WE GOT A GOOD RETURN >. GOTO END >. :BAD >. ECHO WE GOT A BAD RETURN >. GOTO END >. :HAWAII >. ECHO WE ARE GOING TO HAWII >. :END >. EXIT > >the number following 'ERRORLEVEL' will be the number you exited with. He's got the right idea but it won't work as coded. Refer to page 7-34 of DOS 3.2 Reference, paragraph 2 (approx.): "ERRORLEVEL number is true if the previous program had an exit code of number or higher. The number is specified as a decimal value." In order for the above code segment to work you must reverse the order of the IF statements. It would also be wise to cover the case in which the program might return a 3 or greater since in this example you only want to GOTO HAWAII if you get a return of 2. Also note that EXIT won't terminate a batch file and therefore should not be in this code segment. (DOS 3.1, 3.2) Corrected code segment: REM RUN MAIN PROGRAM MAINPGM REM Look at return codes REM A return of 3 or greater is unexpected IF ERRORLEVEL 3 GOTO UNEXPECTED REM Now we can test for 2 (or greater but we've already REM handled values greater than 2) IF ERRORLEVEL 2 GOTO HAWAII REM Test for return of 1 IF ERRORLEVEL 1 GOTO BAD REM Test for return of 0 IF ERRORLEVEL 0 GOTO GOOD :GOOD ECHO WE GOT A GOOD RETURN GOTO END :BAD ECHO WE GOT A BAD RETURN GOTO END :HAWAII ECHO WE ARE GOING TO HAWII GOTO END :UNEXPECTED ECHO Unexpected return value ( >=3 ) :END REM No more commands after this so execution terminates ------------------------------------------------------------------------- Jim Champeaux jvc@mirror.TMC.COM {mit-eddie, ihnp4, wjh12, cca, cbosgd, seismo}!mirror!jvc Mirror Systems, 2067 Massachusetts Avenue, Cambridge, MA 02140 Telephone: (617) 661-0777