I want to be able to tell when my program’s stdout is redirected to a file/device, and when it is left to print normally on the screen. How can this be done in C?
Update 1: From the comments, it seems to be system dependent. If so, then how can this be done with posix-compliant systems?
Perhaps
isatty(stdout)?Edit: As Roland and tripleee suggest, a better answer would be
isatty(STDOUT_FILENO).