Arun Solomon
Arun Solomon

Reputation: 11

My system() command gives some warning which needs to be ignored. How can i hide the warning?

My code : system("systemctl reload httpd");

Upvotes: 0

Views: 95

Answers (1)

Daniel Kleinstein
Daniel Kleinstein

Reputation: 5502

One solution is to modify your system call to something like this:

system("systemctl reload httpd 2> /dev/null");

Another solution if you don't want to modify your system call is to temporarily "disable" stderr (and stdout, if necessary):

#include <unistd.h>

int fd = dup(STDERR_FILENO); // or STDOUT_FILENO

freopen("/dev/null", "w", stderr);
system("systemctl reload httpd");
fflush(stderr);

// restore stderr to its original state
close(STDERR_FILENO);
dup2(fd, STDERR_FILENO);

Upvotes: 2

Related Questions