myfullname
myfullname

Reputation: 41

Strace with redirection

How can I use strace to include output redirection (>), for example:

strace echo Hello > /tmp/file

The output produced is only taking into account echo hello but not > /tmp/file

I have also tried:

alice@vm:~$ strace -e trace=open,close,read,write echo Hello > /tmp/file

close(3)                                = 0
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\34\2\0\0\0\0\0"..., 832) = 832
close(3)                                = 0
close(3)                                = 0
write(1, "Hello\n", 6)                  = 6
close(1)                                = 0
close(2)                                = 0
+++ exited with 0 +++

It shows that it is writing to stdout (file descriptor 1), but no where shows that it is redirecting to /tmp/file.

Upvotes: 4

Views: 2205

Answers (1)

Yam Mesicka
Yam Mesicka

Reputation: 6601

Stracing command with redirection

strace sh -c "echo Hello > /tmp/foo"


Redirecting strace's output to the output stream

From strace man page:

The name of each system call, its arguments and its return value are printed on standard error or to the file specified with the -o option.

So, that's how we can redirect the standard error to some file:

strace echo Hello 2>/tmp/file

Another option is to use the -o flag:

strace -o"/tmp/file2" echo hello

Upvotes: 4

Related Questions