🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.sys.ibm.pc.programmer
2 messages
2 total messages Started by Frank Burleigh Fri, 06 Jul 1990 10:31
Redirecting to/from spawnxx()ed program?
#861
Author: Frank Burleigh
Date: Fri, 06 Jul 1990 10:31
20 lines
1263 bytes
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?

As an example, suppose your program spawned a program that
might need a long list of files and that doesn't in its own
design take a command line option giving a file name of a
file containing those file names.  If one could redirect
such a file into the program, one might avoid rerunning
the spawned program over and over until the list of files
is exhausted.

I'm using TC2/MSC6.

Thanks in advance for any ideas and comments, yea or nea.

-- 
Frank Burleigh  burleigh@cica.cica.indiana.edu
USENET: ...rutgers!iuvax!cica!burleigh BITNET: BURLEIGH@IUBACS.BITNET
Department of Sociology, Indiana University, Bloomington, Indiana 47405
Re: Redirecting to/from spawnxx()ed program?
#890
Author: Simon J. Gerraty
Date: Sun, 08 Jul 1990 23:48
31 lines
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 */
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads