Xref: utzoo comp.sys.ibm.pc.programmer:2305 alt.msdos.programmer:1838 Path: utzoo!attcan!uunet!samsung!usc!hacgate!ladcgw.ladc.bull.com!melb.bull.oz.au!sun0!sjg From: sjg@sun0.melb.bull.oz.au (Simon J. Gerraty) Newsgroups: comp.sys.ibm.pc.programmer,alt.msdos.programmer Subject: Re: Redirecting to/from spawnxx()ed program? Message-ID: <1990Jul8.234836.21615@melb.bull.oz.au> Date: 8 Jul 90 23:48:36 GMT References: <2589@cica.cica.indiana.edu> Sender: news@melb.bull.oz.au Organization: Bull HN Information Systems Australia Lines: 31 In-Reply-To: burleigh@cica.cica.indiana.edu's message of 6 Jul 90 10:31:57 GMT In article <2589@cica.cica.indiana.edu> burleigh@cica.cica.indiana.edu (Frank Burleigh) writes: > The Subject says pretty well what I want: to redirect the > output from, or input to, a program run from one of the > spawnxx() functions. Can it be done? Indeed it can. The process under DOS is: use dup() to save the current stdin and stdout fd's open the desired files.. use dup2() to associate the new fd's with stdin etc do the spawn close the new stdin etc, (don't forget to flush() stdout). use dup2() to again associate the old files with stdin etc. eg. ostdin = dup(0); fp = fopen(name, "r"); nstdin = fileno(fp); dup2(nstdin, 0); ... spawnxxx(...); fclose(fp); dup2(ostdin, 0); fflush(stdout); ... I have removed all the normal error detection for brevity :-) -- Simon J. Gerraty sjg@sun0.melb.bull.oz.au - NET ..!{hplabs,mcvax,nttlab,ukc,uunet}!munnari!sun0.melb.bull.oz.au!sjg - UUCP #include /* imagine something *very* witty here */