How to tell if stderr is directing output to a file?
Try using isatty()
on the file descriptor:
The
isatty()
function determines if the file descriptorfd
refers to a valid terminal type device.The function
fileno()
examines the argument stream and returns its integer descriptor.
Note that stderr
is always on file descriptor 2, so you don't really need fileno()
in this exact case.