Sep 04, 2009 Hi, I'm facing a stupid problem. I have to work with a crappy C library which prints messages on screen using cout. I want to get rid of these messages, but I cannot modify the code (well, I could, but I cannot reinstall it so I have to live with the verbose library). C - the - Redirecting function output to/dev/null redirect to dev null (2) I am using a library that is printing a warning message to cout or cerr.
Hi, all. I am coding in C on Linux, and using an external library provided by others. This library generates a batch of error/warning messages to stdout, which I do not want to see. Before each function call to the external library, I can insert the following:
freopen('/dev/null', 'w', stdout);
However, after the function call I cannot figure out how to reroute stdout to the console. I tried early in the program defining:
FILE *fConsole = stdout;
and then following the function call with
freopen(fConsole, 'w', stdout);
I also tried following the function call with
freopen('CON', 'w', stdout);
Neither worked; all subsequent messages written to stdout continue to go to /dev/null; that is, they disappear. So... how do I get the stdout messages back to the console after my external function has executed? Thanks!
Hi, Try this idea. 1)Open a file in write mode 2)use dup system call to swap the file descriptor to stdout 3)Open a file in write mode 4)use dup system call to swap the file descriptor to stderr 5)call ur functions/library 6)restore the file descriptor back to stdout and stderr. 7)close the file u have to use open call instead of fopen for this. Hope this helps u Raghuram