system() always returns 0?

Simon Elliott sme at computing-maths.cardiff.ac.uk
Wed Feb 1 19:58:59 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?
  
> -- 
> Derek Terveer  det at hawkmoon.MN.ORG || ..!uunet!rosevax!elric!hawkmoon!det

The problem is that system works by constructing a "command /c yourcommand",
thus letting commnad.com do the work of looking down the path, etc.
command.com _always_ succeeds, so system returns 0, always.  You have to do
the work yourself, and use one of the spawn/exec functions if you want
meaningful status information.

I have used this behaviour of command.com in makefiles when i want to
clean up files which may not be there.  Some versions of make will croak
if the file is not there, since the 'del' is a builtin, but command /c del
will always succeed, and the make continues.




-- 
--------------------------------------------------------------------------
Simon Elliott            Internet: sme%v1.cm.cf.ac.uk at cunyvm.cuny.edu
UWCC Computer Centre     JANET:    sme at uk.ac.cf.cm.v1
40/41 Park Place         UUCP:     {backbones}!mcvax!ukc!reading!cf-cm!sme
Cardiff, Wales           PHONE:    +44 222 874300



More information about the Comp.lang.c mailing list