How can I redirect the output of a C program from /dev/tty to /dev/null?
11
votes
2
answers
3767
views
Consider this sample C program which writes to
/dev/tty
and doesn't have command line options to make it not do so.
#include
int main (void) {
FILE* fout = fopen("/dev/tty", "w");
fprintf(fout, "Hello, World!\n");
fclose(fout);
}
How could I redirect the output of it to /dev/null
in a shell script?
P.S. I read [this answer](https://unix.stackexchange.com/questions/597137/how-to-redirect-output-from-dev-tty-to-dev-null) , but I didn't understand much. In any case, I'm expecting an answer that doesn't modify the code source of the program.
Asked by Firmin Martin
(347 rep)
May 3, 2021, 12:06 PM
Last activity: May 4, 2021, 12:25 PM
Last activity: May 4, 2021, 12:25 PM