🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #2443

Re: MS-DOS EXEC Question

#2443
From: Risto Kankkunen
Date: Sun, 30 Sep 1990 18:03
37 lines
2342 bytes
In article <1990Sep13.162828.5480@mks.com> andy@mks.com (Andy Toy) writes:
>In article <1990Sep9.063941.27673@uwasa.fi> ts@uwasa.fi (Timo Salmi LASK) writes:
>[in Turbo Pascal]
>>SwapVectors;
>>Exec (GetEnv(comspec), '/c ' + 'your command');
>>SwapVectors;
>>If DosError <>0 then whatever;
>
>Is there an equivalent way to do this in Turbo C/C++?  In other words,
>how do you get the return code of 'your command' instead of the return
>code of `comspec' (command.com) which is usually zero since command.com
>doesn't return the return code of the command run with `/c' option.

Unfortunately, the code Timo Salmi showed above doesn't do what you
want in TP either. DosError variable simply tells if the exec call
succeeded, i.e. whether TP could start the program. In C you get this
info from the return value of the execXX call, I think.

There is a function in TP, DosExitCode, that returns the exit code of a
child program. But as you say, command.com doesn't pass the exit code
of programs run by it. So DosExitCode would return always 0. If "your
command" is a EXE or COM program, you could invoke it directly without
command.com, and then DosExitCode works. DosExitCode corresponds to the
DOS call INT 21H/AH=4DH (WAIT), so if TC doesn't have a library
function for this, you could use the DOS call directly.

>Does SwapVector do some magic to get the return code of `your command'
>instead of that of command.com?

SwapVectors only restores the original interrupt vectors for the
duration of the child program. It doesn't have anything to do with the
return codes.

-- 
 Risto Kankkunen                   kankkune@cs.Helsinki.FI (Internet)
 Department of Computer Science    rkankkunen@finuh         (Bitnet)
 University of Helsinki, Finland   ..!mcvax!uhecs!kankkune   (UUCP)
Technical Details
Message-ID: <7686@hydra.Helsinki.FI>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!mit-eddie!bloom-beacon!eru!hagbard!sunic!news.funet.fi!hydra!kankkune
References: <eJB8o4w163w@mudos.ann-arbor.mi.us> <1990Sep9.063941.27673@uwasa.fi> <1990Sep13.162828.5480@mks.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!rutgers!mit-eddie!bloom-beacon!eru!hagbard!sunic!news.funet.fi!hydra!kankkune
From: kankkune@cs.Helsinki.FI (Risto Kankkunen)
Newsgroups: comp.os.msdos.programmer
Subject: Re: MS-DOS EXEC Question
Message-ID: <7686@hydra.Helsinki.FI>
Date: 30 Sep 90 18:03:02 GMT
References: <eJB8o4w163w@mudos.ann-arbor.mi.us> <1990Sep9.063941.27673@uwasa.fi> <1990Sep13.162828.5480@mks.com>
Organization: University of Helsinki, Department of Computer Science
Lines: 37