Xref: utzoo comp.unix.internals:2338 comp.unix.questions:29451 Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.internals,comp.unix.questions Subject: Re: Redirection of stderr Keywords: stderr Message-ID: <1991Mar14.220650.11736@athena.mit.edu> Date: 14 Mar 91 22:06:50 GMT References: <574@dprmpt.UUCP> Sender: news@athena.mit.edu (News system) Followup-To: comp.unix.questions Distribution: na Organization: Massachusetts Institute of Technology Lines: 21 In article <574@dprmpt.UUCP>, larry@dprmpt.UUCP (Larry) writes: |> 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? This is not a comp.unix.wizards question. I have cross-posted this response to comp.unix.questions and directed followups there. First, "stderr_fd = dup(fileno(stderr))" to preserve the original stderr output direction. Then "fclose(stderr)", and immediately do "stderr = fopen(your_stderr_file, "w")" (the "immediately" is so that the newly opened file will get the same file descriptor stderr had, in case you've got that file descriptor hard-coded somewhere in your code). When you're done, "fclose(stderr)" and do "stderr = fdopen(stderr_fd, "w")" to put things back the way they were originally. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710