redirecting output

Larry Jones scjones at thor
Fri Jun 29 22:36:17 AEST 1990


In article <JASON.90Jun28152010 at oswine.cs.odu.edu>, jason at cs.odu.edu (Jason C Austin) writes:
> 	freopen( "filename", "w", stdout );
> 
> 	Anything sent to stdout after this command is executed will go
> to filename.  The function returns the previous value of stdout, so
> you'll probably want to keep it and restore the value, if you want to
> start sending things back to the screen.

No, freopen does NOT return the previous value of stdout, it returns
the current value of stdout (which should, I think, be the same).
The old file has been CLOSED, so there is no way to continue sending
data to it without reopening it, which you probably can't do since
you probably don't know its name.

freopen is portable and works fine for a permanent diversion.  For a
temporary diversion, you have to do something system dependent.  On
most unix systems you need to use fileno, dup, and fdopen to make it
all work.
----
Larry Jones                         UUCP: uunet!sdrc!scjones
SDRC                                      scjones at SDRC.UU.NET
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150-2789             AT&T: (513) 576-2070
"This probably just goes to show something, but I sure don't know what."
-Calvin



More information about the Comp.lang.c mailing list