Xref: utzoo comp.sys.ibm.pc:24199 comp.lang.c:16014 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!ucsd!ucsdhub!hp-sdd!ncr-sd!ncrlnk!uunet!mcvax!ukc!reading!cf-cm!sme From: sme@computing-maths.cardiff.ac.uk (Simon Elliott) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: system() always returns 0? Summary: system starts up command.com, which always succeeds Keywords: MSC5.0 Message-ID: <611@cf-cm.UUCP> Date: 1 Feb 89 09:58:59 GMT References: <782@hawkmoon.MN.ORG> Organization: University of Wales College of Cardiff, Cardiff, WALES, UK. Lines: 28 In article <782@hawkmoon.MN.ORG>, det@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@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@cunyvm.cuny.edu UWCC Computer Centre JANET: sme@uk.ac.cf.cm.v1 40/41 Park Place UUCP: {backbones}!mcvax!ukc!reading!cf-cm!sme Cardiff, Wales PHONE: +44 222 874300