system() always returns 0?

Brent K. Barrett bkbarret at sactoh0.UUCP
Wed Jan 25 05:11:04 AEST 1989


In article <2439 at nunki.usc.edu>, jeenglis at nunki.usc.edu (Joe English) writes:
> 
> 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.)
> 
 That may not be entirely correct, at least as far as TC goes. In
Turbo C 2.0 (and, I believe, 1.5, even though it was not
documented), system() will return 0 if command.com was successfully
loaded, and -1 if command.com was not found. I do not know the ANSI
standard on this beast (if indeed there is one), but since MSC and
TC both have it functioning this way, I'm going to assume it's
ANSI. 
 
 You are correct that spawn()/exec() should be used to return the
proper errorlevels. I ran into this exact same problem a few days
ago when I wanted to run a small utility program externally from a
larger program without removing the larger program from memory. An
errorlevel had to be returned and system() didn't seem to want to
do it. I was confused by the TC 1.0 manual and the 2.0 THELP. The
manual stated that the errorlevel was returned, while the THELP
indicated the true condition. Since I only ordered the upgrade to
2.0, I did not receive a full 2.0 manual, and only have the 1.0
description of system(). Fortunately for me, a Borland beta tester
is easily accessable.
                                  
-- 
 "Somebody help me! I'm trapped in this computer!"
  
 Brent Barrett ..pacbell!sactoh0!bkbarret GEMAIL: B.K.BARRETT



More information about the Comp.lang.c mailing list