Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ames!xanth!xanth.cs.odu.edu!jason From: jason@cs.odu.edu (Jason C Austin) Newsgroups: comp.lang.c Subject: Re: redirecting output Message-ID: Date: 28 Jun 90 19:20:10 GMT References: <22931@dartvax.Dartmouth.EDU> Sender: news@cs.odu.edu Distribution: na Organization: Old Dominion University, Norfolk, VA Lines: 40 In-reply-to: emf@eleazar.dartmouth.edu's message of 27 Jun 90 19:50:17 GMT In article <22931@dartvax.Dartmouth.EDU> emf@eleazar.dartmouth.edu (Eric Friets) writes: -> -> I need to redirect output in the middle of a program -> from the standard output to a file. The use of -> fprintf is ruled out because I do not have the -> source of the functions whose output I want. -> -> Options that are not acceptable: -> 1. redirect output of the entire program, as in -> prog > file -> 2. have the rest of the program write to stderr, and -> then redirect the entire program, as above -> 3. write the necessary data to a file, and have a -> smaller program that redirects to a file -> -> What is really needed is a way to change the pointer -> to stdout to a file pointer returned by fopen(). Any -> suggestions would be appreciated. I will summarize and -> post responses that are mailed to me. -> -> Eric Friets -> emf@eleazar.dartmouth.edu -> . freopen will do the job for you. In fact the unix manual page says that this command is mostly used for this purpose. 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. -- Jason C. Austin jason@cs.odu.edu