Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable std::cerr?

I got a program which contains a lot of std::cerr, it directly outputs to my terminal. I am wondering what is the difference between std::cerr and std::cout. And how can I disable the std::cerr (I don't want it output to my screen)?

like image 887
Joe SHI Avatar asked Aug 18 '11 16:08

Joe SHI


1 Answers

As others have mentioned, if this is a Unix-like system then 2>/dev/null redirects stderr (2) to the big bit bucket in the sky (/dev/null).

But nobody here has explained what the difference between stderr and stdout is, so I feel obligated to at least touch on the topic.

std::cout is the standard output stream. This is typically where your program should output messages.

std::cerr is the standard error stream. This is usually used for error messages.

As such, if your program "contains lots of cerr" output, then it might be worth taking a look at why so many error messages are being printed, rather than simply hiding the messages. This is assuming, of course, that you don't just happen to have a program that emits lots of non-error output to stderr for some reason.

like image 107
Jared Ng Avatar answered Sep 30 '22 12:09

Jared Ng