将某些内容发送到标准错误的可能形式

发布于 2024-11-16 16:06:08 字数 353 浏览 0 评论 0原文

我正在处理一个程序的输出,我有 C++ 源代码。程序将输出发送到 stderr,我需要知道源代码中输出的计算位置/方式。

我知道向 stderr 发送内容的一种形式是

std::cerr << "foo";

我使用 grep 来查看是否使用了该形式,但我找不到它。

我知道它被写入 stderr,因为当我运行程序时,我获得以下形式的输出:

./program 2> file-with-info.txt

是否有其他方式将输出发送到 stderr?有人可以建议我可以 grep 查找此输出发送到哪里的模式吗?

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> file-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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小兔几 2024-11-23 16:06:08

不是,

cerr < "foo"

但是

cerr << "foo"

您也可以尝试 grep for clog(重定向到标准错误流):

clog <<

您还可以搜索 stderr 和 perror,它们是输出到标准错误的旧 C 方法

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

蝶…霜飞 2024-11-23 16:06:08

std::cerrstd::clogstderr 这三个都表示标准错误流。前两个是(无缓冲和缓冲)C++ 接口,第三个是旧的 C stdio 接口。 perror 也写入标准错误。

根据平台的不同,可能有更多方式输出到标准错误,例如在 Unix 上写入文件描述符 2。 (如果幸运的话,您可以 grep 查找符号常量 STDERR_FILENO。)

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.)

我爱人 2024-11-23 16:06:08

最可靠的做法是挂钩写入的操作系统函数,如果它正在写入标准错误输出,则中断/打印调用堆栈。如果您满足于其他任何要求,那么可以通过多种方式输出它,而无需您找到确切的字符串。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文