开发者

Possible forms to send something to standard error

开发者 https://www.devze.com 2023-03-14 00:23 出处:网络
I\'m working with the output of a program to which I have the C++ source code. The program sends output to stderr, and I need to know where/how the output is calculated in the source code.

I'm working with the output of a program to which I have the C++ source code. The program sends output to stderr, and I need to know where/how the output is calculated in the source code.

I know that one form to send something to stderr is

std::cerr << "foo";

I use grep to see if this form is used, but I can't find it.

I know that is written to stderr because when I run the program I obtain the output in this form:

./program 2> fil开发者_如何转开发e-with-info.txt

Are there any other ways for output to be sent to stderr? Can anybody suggest patterns I might grep for to find where this output is being sent?


It's not

cerr < "foo"

but

cerr << "foo"

You can try to grep for clog (redirected to the standard error stream) too :

clog <<

You can also search for stderr and perror which are the old C ways to output to standard err


std::cerr, std::clog and stderr all three denote the standard error stream. The first two are the (unbuffered and buffered) C++ interfaces, the third is the old C stdio interface. perror also writes to standard error.

Depending on the platform, there may be more ways to output to standard error, such as writing to the file descriptor 2 on Unix. (If you're lucky, you can grep for the symbolic constant STDERR_FILENO.)


The most reliable thing to do would be to hook the OS function that writes out and if it's writing to the Standard error output, then break/print callstack. If you settle for anything else, then there's a dozen ways it can be output without you finding that exact string.

0

精彩评论

暂无评论...
验证码 换一张
取 消