不输出到 STDOUT 的程序的管道输出

发布于 2024-10-15 12:05:56 字数 171 浏览 13 评论 0原文

假设我有一个程序输出到由(必需)参数提供的文件:

./foo -o bar.txt

有什么方法可以欺骗它输出到管道吗?这仅输出到名为 - 的文件。

./foo -o - | less

Say I have a program that outputs to a file which is provided by an (required) argument:

./foo -o bar.txt

Is there any way to trick it into outputting to a pipe? This just outputs to a file named -.

./foo -o - | less

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

围归者 2024-10-22 12:05:56

您可以使用 /dev/stdout 作为文件名:

./foo -o /dev/stdout | less

You can use /dev/stdout as the file name:

./foo -o /dev/stdout | less
挖鼻大婶 2024-10-22 12:05:56

随着文件的增长,这会将 bar.txt 的内容提供给过滤器

tail -f bar.txt | filter

This will feed the contents of bar.txt to filter as the file grows:

tail -f bar.txt | filter
荒人说梦 2024-10-22 12:05:56

其他解决方案,创建命名管道:

mkfifo /tmp/myfifo; ./foo -o /tmp/myfifo
</tmp/myfifo cat -

other solution, create a named pipe:

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