1

I have an executable that I am running on the Raspberry Pi. When the program is run, output is displayed on the terminal, but when I use the redirect operator >, I get nothing in the text file.

./example > examp.txt

I have also tried using the pipe operator and the tee command but when I do this I get nothing in the text file or on the screen. I am unsure what to try next. The output from the executable is a data stream that is updated every few seconds. I would like to capture a couple updates from the executable in a text file.

./example | tee examp.txt

migrated from stackoverflow.com Jan 13 '14 at 0:26

This question came from our site for professional and enthusiast programmers.

  • Does the file exist already and is writable by the user executing the executable? With >> you can append text to a file, a single > overwrites the file (so there's a chance that you overwrite the text with a blank line). – Foo Bar May 27 '14 at 13:57
4

Your executable might be writing to stderr instead of stdout. So it might be worth trying to redirect stdout, e.g.,

./example 2> stderr.txt > stdout.txt # write stdout and stderr to two different files

or

./example 2>&1 > log.txt # redirect stderr to stdout and then write them together into one 

file

Further, your executable might not be writing to either stderr and stdout, e.g., by writing directly to the screen using a library such as curses. In that case, you won't be able to capture its output. It might be worth however to study the executable's documentation if you can give it a command line switch to write to stdout/stderr instead of directly to the screen interactively. An example would be the top command in Linux systems, where you can supply a command line option -b.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy