Article View: comp.sys.ibm.pc.programmer
Article #890Re: Redirecting to/from spawnxx()ed program?
From: Simon J. Gerraty
Date: Sun, 08 Jul 1990 23:48
Date: Sun, 08 Jul 1990 23:48
31 lines
1574 bytes
1574 bytes
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 <disclaimer> /* imagine something *very* witty here */
Technical Details
Message-ID:
<1990Jul8.234836.21615@melb.bull.oz.au>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!usc!hacgate!ladcgw.ladc.bull.com!melb.bull.oz.au!sun0!sjgReferences:
<2589@cica.cica.indiana.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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