Reputation: 10513
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.
Upvotes: 10
Views: 8102
Reputation: 19262
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.
Upvotes: 11
Reputation: 143354
Based on your strace it sounds like the program is testing if stdin and/our stdout is a tty. I've never used it but you could try using empty.sourceforge.net. It's suppose to create a pseudo-tty which should fool your program's check.
Upvotes: 7
Reputation: 58998
Try to redirect a single stream at a time to /dev/null, to see which one it prints on:
progname > /dev/null
progname 2> /dev/null
Then you'll see which stream you have to capture. For technical reasons some programs print even informational messages on stdout.
Upvotes: 2