Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C program output should go to console, but should not be redirectable

Tags:

c

linux

I want my_custom_print() output to appear on console. But if the program's stderror or stdout is redirected from shell, they should get redirected (as normal), but the output from my_custom_print() should get ignored.

Is it possible to write my_custom_print() satisfying above condition ? If possible, how?

like image 722
Lunar Mushrooms Avatar asked Nov 21 '11 10:11

Lunar Mushrooms


2 Answers

You can try opening /dev/tty, but it doesn't necessarily exist, if your program run from the environment with no tty.

like image 189
Michael Krelin - hacker Avatar answered Nov 03 '22 07:11

Michael Krelin - hacker


Maybe isatty or /dev/tty could be useful to you.

like image 34
Basile Starynkevitch Avatar answered Nov 03 '22 08:11

Basile Starynkevitch