bash 如何重定向 Valgrind 正在运行的程序的输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30454637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to redirect the output of the program Valgrind is running on?
提问by Mateusz Piotrowski
Background of the question:
问题背景:
I run a command like this:
我运行这样的命令:
$ valgrind ./my_program < 1.in
And I get Valgrind's messages about leaks and errors as well as the output stdout and stderr streams of the my_program.
我收到 Valgrind 的关于泄漏和错误的消息,以及 my_program 的输出标准输出和标准错误流。
Question:
题:
I would like to redirect/mute all the streams of my_program (both stdout and stderr).
我想重定向/静音 my_program 的所有流(标准输出和标准错误)。
Where's what I've learnt so far:
到目前为止我学到了什么:
Running
> /dev/null
doesn't mute the stderr stream of my_program.Running
> /dev/null 2> /dev/null
mutes all the output stream of my_program all together with Valgrind's messages.According to this thread: How to redirect Valgrind's output to a file?Valgrind is capable of streaming its output directly to a log file using
valgrind --log-file="filename"
.
运行
> /dev/null
不会使 my_program 的 stderr 流静音。运行
> /dev/null 2> /dev/null
将 my_program 的所有输出流与 Valgrind 的消息一起静音。根据这个线程:How to redirect Valgrind's output to a file? Valgrind 能够使用
valgrind --log-file="filename"
.
Possible solution:
可能的解决方案:
I've came up with a solution like this
我想出了这样的解决方案
$ valgrind --log-file="filename" ./my_program < 1.in && cat filename
Is there an easier way to do this?
有没有更简单的方法来做到这一点?
回答by doqtor
To separate valgrind and application output you can redirect valgrind output to another file descriptor:
valgrind --log-fd=9 9>>test.log ./app
要分离 valgrind 和应用程序输出,您可以将 valgrind 输出重定向到另一个文件描述符:
valgrind --log-fd=9 9>>test.log ./app
回答by Will C
This may be a little late to the punch, but I'm running valgrind 3.10.1 on ubuntu, and you can simply use the --log-file=<filename>
flag.
I.E. run:
这可能有点晚了,但我在 ubuntu 上运行 valgrind 3.10.1,您可以简单地使用该--log-file=<filename>
标志。IE运行:
valgrind [args] --log-file=<filename> ./my_program