Output redirection doesn't work for a certain program

kshahar picture kshahar · Dec 16, 2010 · Viewed 7k times · Source

On Linux, I'm trying to redirect stdout from a console application to a file instead of console. I do not have the source code. I tried several methods but all resulted in an empty file. Without output redirection everything works fine (I see console messages).

I tried, for example:

progname > out.txt
progname > out.txt 2&>1

And nothing appears in out.txt and in the console.

I tried to run the application with strace. When I do not use redirection, I see lines such as -

write(1, "bla bla", 8)

When I introduce output redirection, there are no write calls at all, which makes me think the application is testing for something before writing the message. What is the application looking for? How can I bypass it?

I'm using CentOS 5.5 and Bash.

Answer

plundra picture plundra · Dec 16, 2010
progname > out.txt 2>&1

Edit: If you actually did this and it was a typo in your question. It might be possible that the application checks if the output is a TTY.

Edit2: Ok, in that case, try script -qc progname > out.txt > 2>&1

In Debian/Ubuntu, script is a part of the bsdutils package which is an Essential package and always installed.