将某些内容发送到标准错误的可能形式
我正在处理一个程序的输出,我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不是,
但是
您也可以尝试 grep for clog(重定向到标准错误流):
您还可以搜索 stderr 和 perror,它们是输出到标准错误的旧 C 方法
It's not
but
You can try to grep for clog (redirected to the standard error stream) too :
You can also search for stderr and perror which are the old C ways to output to standard err
std::cerr
、std::clog
和stderr
这三个都表示标准错误流。前两个是(无缓冲和缓冲)C++ 接口,第三个是旧的 Cstdio
接口。perror
也写入标准错误。根据平台的不同,可能有更多方式输出到标准错误,例如在 Unix 上写入文件描述符 2。 (如果幸运的话,您可以 grep 查找符号常量
STDERR_FILENO
。)std::cerr
,std::clog
andstderr
all three denote the standard error stream. The first two are the (unbuffered and buffered) C++ interfaces, the third is the old Cstdio
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.