输出重定向不适用于特定程序

发布于 2024-10-07 13:23:57 字数 443 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无法言说的痛 2024-10-14 13:23:57
progname > out.txt 2>&1

编辑:如果您确实这样做了,并且这是您问题中的拼写错误。应用程序可能会检查输出是否为 TTY。

编辑2:好的,在这种情况下,尝试script -qc progname >输出.txt> 2>&1

在 Debian/Ubuntu 中,scriptbsdutils 软件包的一部分,该软件包是 Essential 软件包并且始终安装。

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.

疾风者 2024-10-14 13:23:57

根据您的 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.

○闲身 2024-10-14 13:23:57

尝试一次将一个流重定向到 /dev/null,以查看它打印在哪一个流上:

progname > /dev/null
progname 2> /dev/null

然后您将看到必须捕获哪个流。由于技术原因,某些程序甚至在标准输出上打印信息性消息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文