LambdaBeta
LambdaBeta

Reputation: 1505

tee /dev/null consuming input?

Somehow it seems as though running ./program | tee /dev/null is consuming its output. When run on its own, the program prints some text, then continues running while communicating over UDP sockets. It produces a lot of log messages that I wanted to view in a filtered way, so I tried running ./program | grep -v "I dont wan't to see logs like this!" | tail -f but it produced no output. I gave up a bit and decided to just tee the output to another file which I could then inspect with my editor, but it resulted in an empty file.

The program in question was written by a student and so the problem may be within it. What could cause this behaviour? How can I correct it?

Summary:

./program prints output but ./program | tee /dev/null doesn't print anything. Problem possibly within source of ./program, but how to use it properly anyways?

Upvotes: 0

Views: 1124

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126418

This generally happens when the program in question checks to see if it is conncted to a terminal and does something different for terminal vs non-terminal. The easiest way to get around this and capture the output anyways is to use script:

script -c "./program" /dev/stdout | grep -v "I dont wan't to see logs like this!" | tail -f

script will run the program in a pseudo-terminal (so it will think it is connected to a terminal) and and write the output to /dev/stdout which is then piped to grep.

You might also want the -f argument to script to make it flush output after every write (otherwise things will get buffered before writing to the pipe).

Upvotes: 1

Related Questions