Xref: utzoo comp.sys.ibm.pc:23718 comp.lang.c:15773 Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!mailrus!iuvax!bobmon From: bobmon@iuvax.cs.indiana.edu (RAMontante) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: system() always returns 0? Yep... Keywords: MSC5. TC Message-ID: <16825@iuvax.cs.indiana.edu> Date: 25 Jan 89 04:18:49 GMT References: <782@hawkmoon.MN.ORG> <2439@nunki.usc.edu> <646@sactoh0.UUCP> Reply-To: bobmon@iuvax.cs.indiana.edu (RAMontante) Distribution: na Organization: malkaryotic Lines: 31 [ The "system()" returns 0 after invoking COMMAND.COM, in MSC and TC on MSDOS machines ] <646@sactoh0.UUCP> bkbarret@sactoh0.UUCP (Brent K. Barrett): > > 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. "System()" in Turbo C is specifically defined to "...invoke COMMAND.COM to execute a command...". In TCv1.5 the return value is described as the exit status of COMMAND.COM. Unfortunately (but not surprisingly) COMMAND.COM exits with a 0 if it successfully loads and runs, whether the executable file that it was supposed to execute was successful or not. So the only information that you can get back from COMMAND.COM is whether it (loaded and) ran, or crashed the whole dam' machine; nothing about what it did while it was running. This has nothing to do with ANSI, which doesn't specify the behavior of MSDOS. The C "system()" call is doing what it should, but what it receives from the operating system isn't any use to anyone (except in the case of a missing COMMAND.COM file). > You are correct that spawn()/exec() should be used to return the >proper errorlevels. No problem here, as COMMAND.COM isn't involved. The executed file is responsible for returning a meaningful value to spawn() / exec().