Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!voder!berlioz.nsc.com!nelson From: nelson@berlioz.nsc.com (Taed Nelson) Newsgroups: comp.unix.questions Subject: Redirecting stdout, and then getting it back Message-ID: <1991Feb14.035930.20173@berlioz.nsc.com> Date: 14 Feb 91 03:59:30 GMT Sender: nelson@dtg.nsc.com (Taed Nelson) Organization: National Semiconductor Corporation Lines: 22 We have a "shell" program which executes programs from within it using the system()/spawn() call. We wanted to trap these errors, so we freopen()ed stdout and stderr to files that we could parse/show to the user from within the "shell". This part works fine. We also want to provide a "subshell" capability to get out to csh or DOS, but clearly we want stdout and stderr to go back to the screen. Unfortunately, freopen() closed the original screen file, so we can't get output to go there. We tried "storing" the FILE struct prior to the freopen(), but that didn't work, we assume because the FILE struct is just a buffer and not a real descriptor of the file. So we need a way to fopen_again(FILE*) or something of the same sort. Or can we get at the real file descriptors, or keep freopen() from closing the original? Help! (Thanks!)