home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
c_all592.arj
/
TI727.ASC
< prev
next >
Wrap
Text File
|
1992-02-25
|
1KB
|
67 lines
PRODUCT : Borland C++ NUMBER : 727
VERSION : 2.0
OS : DOS
DATE : February 25, 1992 PAGE : 1/1
TITLE : Redirecting Output Before Spawn
/************************************************************
How to redirect output before spawning a child process.
************************************************************/
FILE *fp;
int handle;
fp=fopen( <parms. to open file where to redirect stdout> );
/* in this case, use "NUL" as the file, this is DOS's NULL device
*/
handle=dup(fileno(stdout));
dup2(fileno(fp),fileno(stdout));
execlp ( <whatever parameters you need> );
dup2(handle,fileno(stdout));
/*This will duplicate the file handle stdout to the FILE pointer
fp. Then dup2 is used to replace stdout with the new file opened
with fopen. Next, make your call to spawn. Finally, use dup2 with
the saved handle variable to restore stdout. */