Within my C program, I’d like to temporarly redirect stdout to /dev/null (for example). Then,
after writing to /dev/null, I’d like to restore stdout. How do I manage this?
Within my C program, I’d like to temporarly redirect stdout to /dev/null (for example).
Share
On POSIX systems, you can do it as follows:
What you want is not possible in further generality.
Any solution using
freopenis wrong, as it does not allow you to restore the originalstdout. Any solution by assignment tostdoutis wrong, asstdoutis not an lvalue (it’s a macro that expands to an expression of typeFILE *).