输出重定向不适用于特定程序
在 Linux 上,我尝试将 stdout 从控制台应用程序重定向到文件而不是控制台。我没有源代码。我尝试了多种方法,但都得到了一个空文件。如果没有输出重定向,一切都会正常工作(我看到控制台消息)。
例如,我尝试过:
progname > out.txt
progname > out.txt 2&>1
out.txt 和控制台中什么也没有出现。
我尝试使用 strace 运行该应用程序。当我不使用重定向时,我会看到诸如 -
write(1, "bla bla", 8)
当我引入输出重定向时,根本没有写入调用的行,这使我认为应用程序在写入消息之前正在测试某些内容。该应用程序正在寻找什么?我怎样才能绕过它?
我正在使用 CentOS 5.5 和 Bash。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:如果您确实这样做了,并且这是您问题中的拼写错误。应用程序可能会检查输出是否为 TTY。
编辑2:好的,在这种情况下,尝试
script -qc progname >输出.txt> 2>&1
在 Debian/Ubuntu 中,
script
是bsdutils
软件包的一部分,该软件包是 Essential 软件包并且始终安装。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 thebsdutils
package which is an Essential package and always installed.根据您的 strace,听起来程序正在测试 stdin 和/我们的 stdout 是否是 tty。我从未使用过它,但你可以尝试使用empty.sourceforge.net。它应该创建一个伪终端来欺骗你的程序的检查。
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.
尝试一次将一个流重定向到 /dev/null,以查看它打印在哪一个流上:
然后您将看到必须捕获哪个流。由于技术原因,某些程序甚至在标准输出上打印信息性消息。
Try to redirect a single stream at a time to /dev/null, to see which one it prints on:
Then you'll see which stream you have to capture. For technical reasons some programs print even informational messages on stdout.