Strace won't output to file

I have an application which won’t dislpay it’s text (I’m assuming I’m missing a font; although it could just be a kde problem idk)

I’m trying to use strace to troubleshoot it, but I cannot for the life of me get strace to output to a file; or process the output in any way for that matter.

strace /usr/bin/program -o output.txt

Will just fill my terminal with the strace output and not even create a file, much less fill it with anything.

strace /usr/bin/program > output.txt

Same as before except it creates an empty output.txt file

strace /usr/bin/program | grep blabla

Grep command gets entirely ignored.

Am I doing something wrong or what?

Update: Figured out what is actually happening, -o is being read as an argument for the program I’m troubleshooting instead of for strace. Not sure what I can do about it tho.

The above syntax passes -o output.txt as a parameter to /usr/bin/program, not to strace. Try… :arrow_down:

strace -o output.txt /usr/bin/program

Also bear in mind that if you’re going to be using output redirection, then there’s a difference between stdout and stderr. The file is probably empty because strace writes its output to stderr instead of to stdout, whereas your redirection expects stdout to be writing to the file.

A possible workaround could be… :arrow_down:

strace /usr/bin/program 2>&1 > output.txt

Thank you, can’t believe I was making that mistake, I had an example command that got it wrong, and after looking it up I couldn’t find any other direct example commands to correct it :smiley:

1 Like

yes run strace /usr/bin/program > output.txt is as : strace “/usr/bin/program > output.txt”
other workaround (outputs in terminal and file)

strace /usr/bin/program |& tee log.txt

EDIT: ok Aragorn now stderr redirected as you



The terminal displays both stdout and stderr, but when redirecting the output of a command into a file, the streams are separated, and one has to explicitly tell the shell to write stderr to the file together with stdout, or else stderr will simply go to the terminal screen while only stdout ─ which is empty in this case ─ goes to the file.

Piping stdout through tee would not alter things in that regard, because stdout is empty. What you see on the screen is stderr, because the terminal displays both the stdout and stderr streams at the same time.

A few examples follow below ─ the $ is the command prompt… :arrow_down:

$ program                   # stdout and stderr are both displayed on tty

$ program > file.txt        # stdout goes into file.txt; stderr goes to tty

$ program 2> file.txt       # stdout goes to tty; stderr goes into file.txt

$ program 2>&1 > file.txt   # stdout and stderr both go into file.txt

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.