Path: utzoo!attcan!utgpu!watmath!att!dptg!rutgers!tut.cis.ohio-state.edu!ucbvax!pasteur!ames!uhccux!munnari.oz.au!otc!metro!extro!natmlab!ditsyda!mqcomp!jamespw From: jamespw@mqcomp.oz (Warlow) Newsgroups: comp.lang.c Subject: Re: redirecting a child process output to a file Message-ID: <670@mqcomp.oz> Date: 7 Aug 89 00:57:11 GMT References: <8430@techunix.BITNET> Reply-To: jamespw@mqcomp.mq.oz (James Picton-Warlow) Organization: Computing Discipline, Macquarie University Lines: 23 In article <8430@techunix.BITNET> buzy%techunix.bitnet@jade.berkeley.edu (boaz binnun) writes: >I need to redirect the output of a child process to a file, ... >what I did was : > >char *args[] = { "child.exe", "argument", ">", "filename", NULL }; > >and than: > >spawnl(P_WAIT,args[0],args[0],args[1],args[2],args[3],args[4]); This won't work because the indirection operator > is interpreted by the shell, NOT by C. spawnl doesn't invoke the shell so the file child.exe sees the argument '>', which will probably frighten it. If you *really* want to use indirection, something like system("child.exe argument > filename"); will do the trick (but it's awful); otherwise, use fork to explicitly reset stdout yourself: if (fork() == 0) { /* child process */ stdout = freopen("filename", "w", stdout); execl(args[0],args[0],args[1],args[4]); } or some such.