Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!gatech!hubcap!ncrcae!ncr-sd!hp-sdd!hplabs!hpfcdc!hpldola!hpctdlb!hpctdls!wei From: wei@hpctdls.HP.COM (Bill Ives) Newsgroups: comp.lang.c Subject: Re: redirecting a child process output to a file Message-ID: <2150007@hpctdls.HP.COM> Date: 19 Jun 89 14:46:03 GMT References: <8430@techunix.BITNET> Organization: Hewlett-Packard CTD, Colo. Spgs. Lines: 36 To redirect a child's stdout to a file in the way you described does not work because the child process does not parse the ">" out of the command line. When the redirection operators are used they are used on the DOS command line --- where DOS ( namely command.com ) parses them out and determines that redirection is to be done. The same thing works for pipes "|". Since the command.com shell does this parsing and redirection you may invoke it with the child process name and args following like: c:\command.com child.exe > outfile.dat You should get the command.com specification out of your environment by looking at the "COMSPEC=" environment variable. You could also do the redirection yourself by using DOS functions DOS_DUP_HANDLE, DOS_CLOSE .... The idea in using these is to do the same thing the command shell does when it sees the ">" operator. The basic algorithm for doing this is: duplicate your stdout and save the duplicate in a temp variable open the child's stdout file close your stdout handle so the that it may be attached to the file opened above. use DOS_DUP again to attach the opened file to the stdout your stdout is now the file that was opened. invoke the child -- it will inherit the stdout that is attached to the file. restore your own stdout by closing stdout and duping the temp handle saved in the first step. Your stdout will then be restored.