[comp.unix.wizards] Redirection of stderr

larry@dprmpt.UUCP (Larry) (03/14/91)

In a C program, how can I change stderr from wherever it is directed
via the command line to a file, then later revert it back to it's 
original destination?

Seems like it would be possible, but I can't think how to do it.

Thanks,
-- 
* - * - * - * - * - * - * - * - *
* Larry Johnson                 *
* UUCP: ...!uunet!dprmpt!larry  *
* - * - * - * - * - * - * - * - *

torek@elf.ee.lbl.gov (Chris Torek) (03/20/91)

In article <524@bria> uunet!bria!mike writes:
>#define fdup2(A,B)	(memcpy(B,A,sizeof(FILE)))	/* UGLY */

Not only that, it does not work---because there is no guarantee that
a FILE object holds the state.  In particular, in some System V stdio's,
one or more of the fields in a FILE object is an index into a completely
separate object.  To duplicate the state of one FILE, you must copy
not only that one FILE object but also any objects to which it points,
and there is no way to find those (unless you write your own stdio).
-- 
In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427)
Berkeley, CA		Domain:	torek@ee.lbl.gov