Xref: utzoo comp.sys.ibm.pc:23667 comp.lang.c:15745 Path: utzoo!attcan!uunet!lll-winken!ames!ucsd!orion.cf.uci.edu!oberon!nunki.usc.edu!jeenglis From: jeenglis@nunki.usc.edu (Joe English) Newsgroups: comp.sys.ibm.pc,comp.lang.c Subject: Re: system() always returns 0? Summary: Mostly. Keywords: MSC5.0 Message-ID: <2439@nunki.usc.edu> Date: 24 Jan 89 05:07:30 GMT References: <782@hawkmoon.MN.ORG> Reply-To: jeenglis@nunki.usc.edu (Joe English) Distribution: na Organization: University of Southern California, Los Angeles, CA Lines: 22 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.) The way to get the return status of the program you're interested in is to use one of the exec or spawn functions, which call the DOS load/exec syscall and bypass command.com. It's possible, though a bit more work, to do redirection with these as well (check out dup() and dup2()); the only thing you can't do is call command.com-resident functions like copy and type. Joe English jeenglis@nunki.usc.edu