🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.ibm.pc
Article #15817

Re: Exit codes, help...

#15817
From: ljz
Date: Sat, 14 Feb 1987 21:38
44 lines
2906 bytes
In article <8137@watdaisy.UUCP> dvadura@watdaisy.UUCP (Dennis Vadura) writes:
>       ... When using Microsoft C 4.0 the spawn... functions return nice
>exit codes from the tasks that you spawn.  The problem lies when you run
>command.com with /C option.  Is there some way to get command.com to return
>a proper exit code based on the exit code of the command it executed.

Unfortunately, the answer is no.  The spawn...  function will return the
exit code that command.com returns, which is "no error" as long as it
found a command to run (irrespective of how the command actually performed).

There is a partial solution to this, however:

I have written my own "system" function that does the following:

	Search in the current directory for the command being run,
	appending .COM, .EXE, and .BAT as suffixes to the command (in
	that order).  If the file is found, run it through spawn
	directly in the case of .COM or .EXE and through "command.com
	/c" in the case of the .BAT suffix.  If the file isn't found,
	try the same thing in each directory in the user's PATH
	(accessible via getenv() in Microsoft C).  If a file still isn't
	found, run the command through "command.com /c".  In the cases
	where you are running a .COM or .EXE file through spawn the
	return code will be accessible.  In the case where you had to
	send the command through "command.com /c" it won't, but this
	will only occur if the command is a .BAT file or an internal DOS
	command (such as DIR).  For the sake of efficiency, you
	shouldn't use the "p" versions of spawn to run the command in
	this case (i.e., use 'spawnl' instead of 'spawnlp' and use
	'spawnv' instead of 'spawnvp').  These "p" versions have code in
	them to test whether a PATH search is necessary, and since you
	will have already done one, that code would be superfluous.

This should get you most of the way there with regard to return codes.

If anyone wants this "system" function, email me at the below address.
I'd have to dig it out of my archives and remove some program-specific
stuff from it, so try the above yourself first ... it should be
straightforward.  If enough people really want it and don't want to
try it themselves, I'll clean my version up and post it here.

Lloyd Zusman
Master Byte Software
...!hplabs!well!ljz
Technical Details
Message-ID: <2586@well.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!lll-lcc!well!ljz
References: <8137@watdaisy.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!lll-lcc!well!ljz
From: ljz@well.UUCP
Newsgroups: comp.sys.ibm.pc
Subject: Re: Exit codes, help...
Message-ID: <2586@well.UUCP>
Date: Sat, 14-Feb-87 16:38:07 EST
Article-I.D.: well.2586
Posted: Sat Feb 14 16:38:07 1987
Date-Received: Sun, 15-Feb-87 07:37:18 EST
References: <8137@watdaisy.UUCP>
Reply-To: ljz@well.UUCP (Lloyd Zusman)
Distribution: world
Organization: Whole Earth 'Lectronic Link, Sausalito, CA
Lines: 44
Keywords: exit codes
Summary: Sorry, but ...