I'm writing a C program that outputs to stdout and errors to stderr. The program takes a command such as:
./myprogram function_to_run file_to_read
My program can either output to stdout or be directed to output a file, but it must not be redirected to /dev/null. For example:
./myprogram function_to_run file_to_read //OK
./myprogram function_to_run file_to_read > file.txt //OK
./myprogram function_to_run file_to_read > /dev/null // NOT OK, should produce error in stderr
I tried to use isatty(1), but it only can detect if stdout is outputting to a terminal. Therefore, it fails for the case where stdout is redirected to a file, which is acceptable in my case
Is there a way to check for this in C? If not, any suggestion how I could check for the /dev/null scenario?