How to determine the destination of standard output?

YANG Liqun yang at nff.ncl.omron.co.jp
Fri Feb 8 16:36:38 AEST 1991


<ping at cubmol.bio.columbia.edu(Shiping Zhang)> writes:

>I'm not sure if this subject has be discussed before. I want to know
>if there is a way to tell within a program where its standard output
>goes. More specifically, if the output goes to the terminal screen, or
>goes to a pipe, or is redirected into a disk file. Thanks for any info.

If you want to if the standard output is terminal, use ttyname() or isatty.
Otherwise, use
     #include <sys/types.h>
     #include <sys/stat.h>

     fstat(fd, buf)
     int fd;
     struct stat *buf;

check buf->st_mode. 
--
-------------------------------------------------------------------------------
|		Yang Li-qun                                                   |
|		OE, OMRON Corporation                                         |
|		20, Igadera Shimokaiinji Nagaokakyo-City                      |
|		Kyoto 617 Japan                                               |
|		Tel: 075-951-5111  Fax: 075-956-7403                          |
|  		E-mail:yang at nff.ncl.omron.co.jp                               |
-------------------------------------------------------------------------------



More information about the Comp.unix.programmer mailing list