system() always returns 0?

Joe English jeenglis at nunki.usc.edu
Tue Jan 24 15:07:30 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?

That, unfortunately, is right.  system() returns the exit status of
command.com (in Turbo C, anyway, and I suspect that MSC works the same
way), and command.com doesn't return an error code if the called
program fails. (!)  (system() also returns non-zero if command.com could
not be loaded for lack of memory.)

The way to get the return status of the program you're interested in
is to use one of the exec or spawn functions, which call the DOS
load/exec syscall and bypass command.com.  It's possible, though a bit
more work, to do redirection with these as well (check out dup() and
dup2()); the only thing you can't do is call command.com-resident
functions like copy and type.


Joe English
jeenglis at nunki.usc.edu



More information about the Comp.lang.c mailing list