47

I'm trying to run strace trough ccze, and the pipe doesn't work as expected.

The command-line I'm running to test is sudo strace -p $(pgrep apache2) | grep open, and all lines are output, ignoring grep.

Is there something special about strace that causes this behavior?

1 Answer 1

73

strace prints its traces on standard error, not on standard output. That's because it's common to want to redirect the standard output of the program, but usually not a problem that strace's stderr and the program's stderr are mixed.

So you should redirect strace's stderr to stdout to be able to pipe it:

sudo strace -p $(pgrep apache2) 2>&1 | grep open 

except that what you're really looking for is

sudo strace -p $(pgrep apache2) -e open 
5
  • it works!! thank you! - I wasn't actually trying to look only at open calls, I just put that as an example, what I'm really trying to do is color highlighting Commented Sep 15, 2012 at 0:03
  • 1
    I am getting strace: Invalid process id: '-e' with the last command. I am on version 4.8. 2010-03-30. Commented Jun 29, 2017 at 19:13
  • Ahh, I actually have httpd (RHEL). Commented Jun 29, 2017 at 19:21
  • 1
    @ElijahLynn Replace apache2 by the name of the process you're interested in. Check that pgrep prints a single PID, otherwise pick one and run e.g. sudo strace -p 1234 -e open Commented Jun 29, 2017 at 20:34
  • 1
    @Andrei, what about using vim color syntax highlighting? strace $CMD 2>&1 > /dev/null | vim -c ':set syntax=strace' -. Commented Aug 27, 2017 at 14:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.