LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   strace, redirecting to file (https://www.linuxquestions.org/questions/linux-general-1/strace-redirecting-to-file-456212/)

shamgar03 06-19-2006 09:07 AM

strace, redirecting to file
 
I need to re-direct the output of strace to a file. I also need to redirect the output for time to a file. The way these two commands work is like this:
strace [options] <command>
so like "strace ls" for instance. The problem is strace ls > out just redirects the output of ls, not strace. So how would I go about doing this? I know strace has an output file command, but I really would like to be able to do this with the simple > operator since there are quite a few cases where I would like to redirect the output of a command, which calls another command, to a file. Any tips would help.

p.s. | less doesnt work after "strace ls" either

nx5000 06-19-2006 09:12 AM

Like this:
Code:

strace /bin/ls &> /tmp/u

shamgar03 06-19-2006 09:31 AM

Awesome, but why doesn't it work with the time command?
time ls &> out doesn't work, is it not to standard out or standard error?

LOL maybe I should just strace ls =)

nx5000 06-19-2006 09:42 AM

Because you need to redirect the whole in a subshell, not only the last command
Code:

(time /bin/ls) &> /tmp/u

shamgar03 06-19-2006 01:08 PM

Thanks man, I tried parenthesis before, but not WITH &. Very helpful

jlliagre 06-19-2006 02:33 PM

Quote:

p.s. | less doesnt work after "strace ls" either
Try this:

Code:

strace ls 2>&1 | less

shamgar03 06-19-2006 03:05 PM

Quote:

Originally Posted by jlliagre
Try this:

Code:

strace ls 2>&1 | less

Nice, similiar effect as parenthesis, but it sort of shows whats going on, so I can still redirect ls to a file, and then pipe strace to less. Thanks alot guys

nx5000 06-20-2006 06:41 AM

You might also be interested in the command tee
Code:

(time /bin/ls) 2>&1 | tee /tmp/u


All times are GMT -5. The time now is 06:37 AM.