How to redirect stdout back to terminal window

I need to redirect some output, which is usually printed on the screen to a file. I was able to redirect the output to a file, but I cannot figure out how to redirect the output of the rest of my program back to the terminal window.

All code is in C. The program runs on Ubuntu.

Any understanding of what needs to be done?

+3
source share
2 answers

I assume that you start with standard output unirectirected. Then you close the original standard output and open it again to send the standard output to a file - perhaps using freopen(). When you finish writing to a file, you want to reconnect standard output to the terminal.

, , , freopen(), /dev/tty. , ; (, cron), /dev/tty .

( ), , , , , .

, dup() . dup() .

+5

, , , , - . , . .

, tee (1).

+1
source

Source: https://habr.com/ru/post/1793329/


All Articles