home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sunquest!apollo.sunquest.com!ahd
- From: ahd@apollo.sunquest.com (Art Dyer)
- Newsgroups: comp.lang.c
- Subject: Re: stderr: Question
- Keywords: fprintf stderr
- Message-ID: <55458@sunquest.UUCP>
- Date: 28 Dec 92 16:24:45 GMT
- References: <1992Dec21.134608.16856@ifi.unizh.ch>
- Sender: news@sunquest.UUCP
- Organization: Sunquest Information Systems, Tucson
- Lines: 22
-
- In article <1992Dec21.134608.16856@ifi.unizh.ch>,
- caliaro@avalon.physik.unizh.ch (Aurelio Caliaro) writes:
-
- > I would like to redirect all output made by "fprintf(stderr, ...)" to
- > a procedure. Is that possible without changing the source everytime
- > that stderr comes?
-
- I've used the following technique:
- Create a pipe, let's call it p.
- Close file descriptor 2.
- Use fcntl(p[1], F_DUPFD, 2) to re-open file descriptor 2 as
- as duplicate of the writable side of your pipe.
- Now, when somebody writes to stderr (or directly to file
- descriptor 2), the data goes into your pipe and thus is
- available for reading from p[0]. If you have asynch i/o
- capability you can set up a signal handler to be called
- whenever data is available to be read, otherwise you will
- need to poll the pipe.
- Apologies for posting a UNIX-oriented reply in a C-oriented group.
-
- --
- Art Dyer ahd@apollo.sunquest.com Voice: (602) 570-2602
-