Mateusz Piotrowski
Mateusz Piotrowski

Reputation: 9117

How to redirect the output of the program Valgrind is running on?

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.

Question:

I would like to redirect/mute all the streams of my_program (both stdout and stderr).

Where's what I've learnt so far:

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?

Upvotes: 5

Views: 9024

Answers (3)

user4815162342
user4815162342

Reputation: 2077

As I understood the question, this is the answer that I found works for me:

valgrind --log-fd=9 [program]  9>&1 1>/dev/null 2>/dev/null

This outputs the valgrind messages to stdout, but the stdout and stderr from the program goes to /dev/null. The order of the redirects is important, as described here.

A "-q" option will also restrict valgrind to errors only.

Upvotes: 0

Will C
Will C

Reputation: 317

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:

valgrind [args] --log-file=<filename> ./my_program

Upvotes: 6

doqtor
doqtor

Reputation: 8484

To separate valgrind and application output you can redirect valgrind output to another file descriptor: valgrind --log-fd=9 9>>test.log ./app

Upvotes: 11

Related Questions