evoliptic
evoliptic

Reputation: 343

How to put a pipe as input for valgrind?

I would like to check my program memory using almost automated tools (I'm not good at gdb yet), and so I ended up using valgrind.

However, I would like to put a pipe as the input of valgrind; i.e. I would like to put the following:

 >cat file.h | ./prog 

I tried to make a

 >valgrind `cat file.h | ./prog`

without success.

I also tried to make a script file where I put the whole command, and then pass it to valgrind, with no more success.

Upvotes: 14

Views: 8396

Answers (1)

Owen DeLong
Owen DeLong

Reputation: 117

As mentioned in the comments, you should be able to use either of:

cat file.h | valgrind ./prog
valgrind ./prog < file.h

The first one uses a pipe as you specifically requested and could just as easily be the output of any program e.g.

ls -al | valgrind ./prog
ps -axuwww | valgrind ./prog

The latter one is more efficient if you're just trying to grab the contents of a file.

The backtick method you tried is not for what you are doing here. It's for situations where you want the output of one command to be the arguments for another (e.g. ls -al cat namelist to do a long detailed listing of all files named in in a file called nameless).

Upvotes: 2

Related Questions