Xref: utzoo comp.sys.ibm.pc:23699 comp.lang.c:15763 Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!pacbell!sactoh0!bkbarret From: bkbarret@sactoh0.UUCP (Brent K. Barrett) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: system() always returns 0? Summary: Mayhaps not quite correct... Keywords: MSC5. Message-ID: <646@sactoh0.UUCP> Date: 24 Jan 89 19:11:04 GMT References: <782@hawkmoon.MN.ORG> <2439@nunki.usc.edu> Distribution: na Organization: Sacramento Public Access, Ca. USA Lines: 37 In article <2439@nunki.usc.edu>, jeenglis@nunki.usc.edu (Joe English) writes: > > 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? > > 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