Redirection of stderr
Jonathan I. Kamens
jik at athena.mit.edu
Fri Mar 15 08:50:58 AEST 1991
Someone has pointed out to me in E-mail that assigning to stderr as I
indicated in my previous message won't work on many systems because of the way
stderr is defined.
There are ways to get around this. One of them, a rather gross method that
will nonetheless work on many systems, is to assign to stderr like this:
*(stderr) = *(value to assign)
e.g.
*(stderr) = *(fopen(error_file, "w"));
However, this won't work if FILE * is an opaque type whose contents are not
spelled out for the compiler in <stdio.h>.
It is possible to replace stderr with a file doing something like this:
freopen(error_file, "w", stderr);
However, if you do things this way, I can't see any way to put the original
stderr back in place -- there is no "fdreopen". That's unfortunate.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.questions
mailing list