Redirecting stdout, and then getting it back

Taed Nelson nelson at berlioz.nsc.com
Thu Feb 14 14:59:30 AEST 1991


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!)



More information about the Comp.unix.questions mailing list