When you call system()from C, the shell is called to interpret your command. This means that you can use shell redirects:
system("ls > /dev/null");
and if you want errors to be suppressed as well
system("ls > /dev/null 2>&1");
However, due to the overhead of running the shell and the fragility of building shell commands, it is best to avoid system()when you can.
source
share