打印fifo内容并退出
我需要将 fifo(命名管道)的内容打印到标准输出。
我可以使用命令:
cat fifo
问题是 cat
没有返回。 它保持运行状态,等待来自 fifo 的更多内容。 但我知道一段时间内不会有更多内容,所以我只想打印可用的内容。
是否有一个命令只打印可用内容并退出?
编辑:
在 fifo 的一端有一个进程时不时地写入不同命令的输出。 该进程永久运行,因此不会出现 EOF。
I need to print the content of a fifo (named pipe) to standard output.
I could use the command:
cat fifo
The problem is that cat
doesn't return. It stays running, waiting for more content coming from the fifo. But I know there wont be any more content coming for a while so I just want to print what's available.
Is there a command that just print the available content and exit??
EDIT:
In one end of the fifo there is a process writing every now and then the output of different commands. That process is permanently running so there wont be an EOF.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您无法发送 EOF 时,您可以使用“非阻塞猫”。 我已经包含了我发现的(经过测试的)C 版本 这里(当然,归功于那里的原作者)。 神奇之处在于 fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK)。
这个非阻塞猫的第一个参数是您在再次退出之前要等待的秒数。
When you can't send an EOF, you could use a 'non-blocking cat'. I've included a (tested) C version i found here (credit goes to the original author over there of course). The magic is in
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK).
The first argument to this non-blocking cat is the number of seconds you want to wait before exiting again.
您应该关闭 FIFO 的另一端。 这应该向
cat
进程发送一个 EOF。You should close the other end of the FIFO. That should send an EOF to the
cat
process.