Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!shelby!riacs!agate!darkstar!ucscb.UCSC.EDU!funkstr From: funkstr@ucscb.UCSC.EDU (Larry Hastings) Newsgroups: comp.os.msdos.programmer Subject: Re: Child processes in Mess-Dos Message-ID: <7409@darkstar.ucsc.edu> Date: 2 Oct 90 06:50:41 GMT References: <619@demott.COM> <15651@yunexus.YorkU.CA> <4469@bwdls58.UUCP> Sender: usenet@darkstar.ucsc.edu Organization: Knowledge Dynamics Corporation Lines: 59 +-In article <4469@bwdls58.UUCP>, | mlord@bwdls58.bnr.ca (Mark Lord) wrote: | | >>>Others were under the impression that spawn and exec load an additional | >>>copy of COMMAND.COM. I didn't test to see if this is true, but I doubt it. | [other followups deleted] | | Ok.. I believe the difference here is whether or not the complete path is | given for the command. If fully qualified, COMMAND.COM is not needed, | otherwise it probably is needed to do the PATH search and actual invocation. | +---------- Let's clear this all up. Here's the dirt on system() and spawn(), including questions that haven't come up... system() loads another copy of "the command processor" (on DOS, COMMAND.COM) and passes as parameters to the command processor the command you pass to it. The return value of system() is the return value of the command processor -- if it ran successfully, this will be a 0 -- and _not_ the return value of the program itself. spawn() loads the program you specify directly without a command processor under all circumstances. The return value of spawn() commands is the actual return value of the program you ran. There's one side effect of spawn() that you may not have expected: Many standard commands are actually part of the command processor itself (for instance, under DOS CD, COPY, MKDIR, and ECHO are all part of COMMAND.COM) and are _not_ separate programs. (There's no COPY.COM or ECHO.COM on DOS.) This means you _can't_ use spawn() to do a MKDIR, unless you load a copy of the command processor -- which is what system() does _anyway_. (In fact, I'm guessing that in many libraries, system() is just a front-end to spawn().) I haven't used spawn() on UNIX, but on Turbo C and MSC there are six varieties of spawn commands, depending on: * Whether you want the path searched for the program (this is handled by code in the run-time library, NOT by COMMAND.COM) * Whether you want to pass a modified environment to the program (by default, the shell variables from the parent are passed unmodified to the child) * Whether you want to pass the command-line for the program as a "vector" (an array of pointers -- like char *argv[]) or as individual char * arguments (steps off soapbox) I used to work in technical support for a compiler company, and I've answered this question more than once... -- larry hastings, the galactic funkster, funkstr@ucscb.ucsc.edu I don't speak for Knowledge Dynamics or UC Santa Cruz, nor do they speak for me The 4th law of Robotics (courtesy of Lore Shoberg): "A robot must encourage proper dental hygiene, except where such encouragement would interfere with the 0th, 1st, 2nd, and 3rd laws."