rmarks@bbking.PRC.Unisys.COM (richard marks) (12/29/87)
In Turbo Pascal 3.0 how does one return an ErrorLevel code? Can I do a func $4C with the code in AL directly? The exit code from TurboP goes thru all sorts of stuff, so I am a bit leary about doing this. Does one patch or InLine the XOR AX,AX; CALL 0C89 code at the end of a Turbo Pascal program? Is there some way to tell Turbo Pascal to just return a value? Does anyone know how to do this under 4.0 (I have not gotten my copy of 4.0 yet). Thanks, Richard Marks rmarks@PRC.unisys.COM
kirsch@braggvax.arpa (David Kirschbaum) (12/30/87)
Richard asks how to return an ERRORLEVEL value from Turbo Pascal 3.0. Haven't actually tested this, but the manual (p135) on the Procedure Halt says: "In PC/MSDOS, Halt may optionally pass a (sic) integer parameter specifying the return code of the program. Halt without a parameter corresponds to Halt(0). The return code may be examined by the parent process us- ing an MS-DOS system function call or through an ERRORLEVEL test in an MS-DOS batch file." David Kirschbaum Toad Hall
hirayama@suvax1.UUCP (Pat Hirayama) (01/03/88)
in article <11028@brl-adm.ARPA>, kirsch@braggvax.arpa (David Kirschbaum) says: > > Richard asks how to return an ERRORLEVEL value from Turbo Pascal 3.0. > Haven't actually tested this, but the manual (p135) on the Procedure Halt says: > > "In PC/MSDOS, Halt may optionally pass a (sic) integer parameter specifying > the return code of the program. Halt without a parameter corresponds > to Halt(0). The return code may be examined by the parent process us- > ing an MS-DOS system function call or through an ERRORLEVEL test > in an MS-DOS batch file." In TP4.0, the manual (p. 430) states the following about Halt: Function Stops program execution and returns to the operating system. Declaration Halt [ ( exitcode: word ) ] Remarks *exitcode* is an optional expression of type word that specifies the exit code of the program. *Halt* without a parameter corresponds to Halt(0). The exit code can be examined by a parent process using the DosExitCode function in the Dos unit or through an ERRORLEVEL test in a DOS batch file. Note that *Halt* will initiate execution of any unit *Exit* procedures. Also in TP4.0 manual (p.393): DosExitCode function Function Returns the exit code of a subprocess. Declaration DosExitCode Result Type word Remarks The low byte is the code sent by the terminating process. The high byte is 0 for normal termination, 1 if terminated by Ctrl-C, 2 if terminated due to a device error, or 3 if terminated by the Keep procedure. Also in TP4.0 manual (p.438): Keep procedure Function Keep (or Terminate Stay Resident) terminates the program and makes it stay in memory. Declaration Keep(ExitCode: word) Remarks The entire program stays in memory--including data segment, stack segment, and heap--so be sure to specify a maximum size for the heap using the $M compiler directive. The *ExitCode* corresponds to the one passed to the *Halt* standard procedure. Restrictions Use with care! Terminate Stay Resident (TSR) programs are complex and *no* other support for them is provided. Refer to the MS-DOS technical documentation for more information. I hope that some of this helps. ------------------------------------------------------------------------------ - Pat Hirayama - Seattle University E-Mail: ...!dataio!suvax1!hirayama USNail: 28625-47th Place South, Auburn, WA 98001-1140 As soon as a still-to-be finished computer task becomes a life-or-death situation, the power fails. ------------------------------------------------------------------------------
lowey@sask.UUCP (Kevin Lowey) (01/07/88)
In article <23@bbking.PRC.Unisys.COM>, rmarks@bbking.PRC.Unisys.COM (richard marks) writes: > In Turbo Pascal 3.0 how does one return an ErrorLevel code? The Turbo Pascal HALT command can take an optional integer argument. This argument is the errorlevel to be returned. > Does anyone know how to do this under 4.0 (I have not gotten my > copy of 4.0 yet). Yes, this does work with 4.0. Here is a sample turbo pascal program (without any error checking): program test; var errorlevel : integer; {or word in TP 4.0} begin {test} write ('Enter the number to be returned: '); readln (errorlevel); halt(errorlevel); write ('This line is never executed because a HALT exits the program'); end. {test} This program was supplied off the top of my head, but I think it works #:-) Kevin Lowey LOWEY@SASK.BITNET (preferred) ...!ihnp4!sask!lowey.uucp Kevin Lowey at 140/43 (fidonet) klowey (BIX)