system() always returns 0?

Walter Bright bright at Data-IO.COM
Thu Jan 26 05:51:41 AEST 1989


In article <782 at hawkmoon.MN.ORG> det at hawkmoon.MN.ORG (Derek E. Terveer) writes:
>Has anyone encountered a problem with the Microsoft C 5.0 compiler always
>returning a 0 from the system() call, no matter what the actual command
>executed by system() returns?

system("command") on MS-DOS is usually implemented by running COMMAND.COM
with the argument "/c command". The system() call returns the value that
COMMAND.COM returns. COMMAND.COM does not return the exit status of the
command that it executed, so it's a DOS bug, not a compiler library bug.

The correct solution is to use the spawn() function. spawn() also uses
less memory and executes faster than system(). The only caveats are that
spawn() cannot execute COMMAND.COM's built-in commands like TYPE and DIR,
and spawn() does not do the < | > redirection.



More information about the Comp.lang.c mailing list