Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

valgrind

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:

  • 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".

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?

like image 775
Mateusz Piotrowski Avatar asked Dec 15 '22 14:12

Mateusz Piotrowski


1 Answers

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

like image 63
doqtor Avatar answered May 14 '23 11:05

doqtor