Redirecting To Dev Null C Rating: 3,7/5 3147 reviews

Looking for Free VST Piano instrument? Stop by freevst.org, we have collected them here, and just download any you want. Free vst indian instruments download.

Null
Expert100+
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:
  1. 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:
  1. FILE *fConsole = stdout;
and then following the function call with
  1. freopen(fConsole, 'w', stdout);
I also tried following the function call with
  1. 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

Find Dev Null

So in this example, the stdout (1) is being redirected to /dev/null. The null device is a device file that discards all data written to it. Then stderr is then being redirected into stdout (2&1), therefore, both stdout and stderr will go to /dev/null. So placing this at the end of a crontab job will suppress all output and errors from the command. ITworld covers a wide range of technology topics, including software, security, operating systems, mobile, storage, servers and data centers, emerging tech, and technology companies such as.

Coments are closed
Scroll to top