[comp.sys.ibm.pc] Exit codes revisited

dvadura@watdaisy.UUCP (02/15/87)

I have received a number of responses to my previous posting regarding
exit codes from MSC 4.0 when using spawn and system functions.  This is
a summary of those responses and an effort to shed a little more light
on what is going on.

All that I discuss below applies to DOS 3.2, I would be interested to see
if similar behaviour is observed under DOS 3.1.  (I do not have access to
3.1 though)

the system() function in the MSC 4.0 library returns 0 if the command
completed successfully, and -1 otherwise.  No mention of exit code of task
that it was running.  This is fair enough, but is not compatible with BSD 4.2
system() function call which returns the exit status of the shell.

so then you try the next obvious thing, namely: (suggested by a number of
respondents)

spawnlp( P_WAIT, "command.com", "", "/c", command, NULL );

and guess what:  The return code I get back is 0 if the command was
successfully executed independent of the commands status code
and -1 otherwise.  (ie. just like system())
The code to try this is below:

tt.c:
main()
{
   int i;

   /* one that works, ie can find command to execute */
   i = spawnlp( 0, "command.com", "", "/c", "t > hello", 0 );
   printf( "retcode = %d\n", i );

   /* one that doesn't, ie can't find junk */
   i = spawnlp( 0, "command.com", "", "/c", "junk", 0 );
   printf( "retcode = %d\n", i );
}


t.c:
main()
{
   printf( "hello\n" );
   exit( 10 );
}

output: (after running tt.exe)
retcode = 0
command not found
retcode = 0


In otherwords:  When you use command.com to execute the commands, (at least
the version that I have) the exit status of the task that was executed is
not returned.  It appears that command.com is simply returning 0 as
the exit code.  In the second example when junk is not found command.com still
returns 0.

Now for the questions...  Does there exist a version
of command.com that returns the correct exit code?  Better still, is there
a PD version that does this sort of stuff correctly?

-dennis
-- 
--------------------------------------------------------------------------------
Dennis Vadura, Computer Science Dept., University of Waterloo
UUCP:  {ihnp4|allegra|utzoo|utcsri}!watmath!watdaisy!dvadura
================================================================================