通标准输出作为命令行util的文件名? 【答案:命名管道使用] [英] pass stdout as file name for command line util? [answer: use named pipes]
问题描述
我使用需要传递一个文件名来写输出,例如一个命令行实用程序工作。
I'm working with a command line utility that requires passing the name of a file to write output to, e.g.
foo -o output.txt
它写入标准输出
的唯一事情是一条消息,表明它已成功运行。我希望能够将写入 output.txt的
另一个命令行实用程序管一切。我的动机是output.txt的最终会被一个40 GB的文件,我并不需要保留,我宁愿管不是以循序渐进的方式对大量文件的工作流。
The only thing it writes to stdout
is a message that indicates that it ran successfully. I'd like to be able to pipe everything that is written to output.txt
to another command line utility. My motivation is that output.txt will end up being a 40 GB file that I don't need to keep, and I'd rather pipe the streams than work on massive files in a stepwise manner.
有没有办法在这种情况下管道的实际产出(即 output.txt的
)到另一个命令?我可以神奇地通过标准输出
作为文件变量?
Is there any way in this scenario to pipe the real output (i.e. output.txt
) to another command? Can I somehow magically pass stdout
as the file argument?
推荐答案
您需要使用命名管道一个。
You need to use a named pipe.
-
创建使用
mkfifo子
命令命名管道。
mkfifo my_buf
与该文件作为输入
Launch your other command with that file as input
other_command < my_buf
执行富
,让它写它的输出 my_buf
foo -o my_buf
这篇关于通标准输出作为命令行util的文件名? 【答案:命名管道使用]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!