How to determine the destination of standard output?

David Arko darko at hpfcdc.HP.COM
Sat Feb 9 02:32:37 AEST 1991


Any easy way to know if a file descriptor is going to a tty is to use
the isatty(3C) library call on it (ie. if(isatty(1)) ...)

To check if it is going to a pipe, you may have to use the
stat(2),stat(5) (or actually fstat()) system call on file descriptor 1,
and look at the st_mode field, in particular, the S_IFIFO bit field
to tell if stdout is a pipe.  The st_mode field will also tell you if
it is going to a character or block device, or if it is a regular
file... all you ever wanted to know and more..., see the man page for
more detailed

-- David (darko at hpfcrn.fc.hp.com)



More information about the Comp.unix.programmer mailing list