PRODUCT : Borland C++ NUMBER : 727 VERSION : 2.0 OS : DOS DATE : September 18, 1991 PAGE : 1/1 TITLE : Redirecting Output Before Spawn /************************************************************ How to redirect output before spawning a child process. ************************************************************/ FILE *fp; int handle; fp=fopen( ); /* in this case, use "NUL" as the file, this is DOS's NULL device */ handle=dup(fileno(stdout)); dup2(fileno(fp),fileno(stdout)); execlp ( ); 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. */