How to determine file being redirected to in C

Guy Harris guy at auspex.UUCP
Thu Mar 2 06:13:06 AEST 1989


 >You may want to investigate the isatty() function call.  I believe that
 >you can use something like:  isatty(stdout)  which will tell you if
 >standard out is going to a terminal (the usual case), or if it has been
 >redirected via a pipe or into a file.

We've been here before.  No, "isatty(stdout)" won't tell you anything of
the sort.  "isatty" takes a file descriptor, *not* a standard I/O
"FILE *".  "isatty(fileno(stdout))", or "isatty(1)", will tell you
whether the standard output is a tty or not.



More information about the Comp.unix.questions mailing list