多链管道
我绝望,我正在寻找一个月的多链管道的参考/源代码,这意味着我可以运行一些东西:
cat /tmp/test.log | wc -l --> stdout
| grep test1 --> stdout
| grep test2 | grep test3 |
| grep test4 --> stdout
| grep test5 --> stdout
请不要将我发送到bash/tee/$...命令,而 tee 处理文件,而 bash 太复杂而难以理解...
请注意,顺序并不重要,完成的第一个链也将被处理。
I am desperate, I am searching for a month for reference/source code for multi chains of pipes, meaning that I can run something:
cat /tmp/test.log | wc -l --> stdout
| grep test1 --> stdout
| grep test2 | grep test3 |
| grep test4 --> stdout
| grep test5 --> stdout
Please don't send me to bash/tee/$... commands while tee works with files, and bash is too complicated to understand...
Note that the order does not care, the first chain that was finished will be handled as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你或许应该将你正在做的事情分解成多个较小的任务,而不是试图一击粉碎所有事情。这是一个 BASH 脚本,它可以完成您想要的相同操作,但更容易理解。
注意:我没有对此进行测试,因此可能存在问题。
You should probably break what you are doing up into multiple smaller tasks rather than trying to smash everything in one blow. Here is a BASH script that will do the same thing you want, but be much easier to comprehend.
Note: I did not test this, so there may be issues.
实际上我必须为学校项目开发类似的东西。这个想法是概括管道的概念来实现这样的事情:(
循环也是可能的)
为了做到这一点,我的程序做了以下事情:
就我而言,由于调用的进程也是由我开发的,因此我可以将管道文件描述符作为参数传递给子进程(--pipe-in .... --pipe-out ....),但是由于您正在使用基于 stdin/stdout 的现有程序,因此您可以使用 dup2() 来“复制”标准 I/O 管道。
我不知道你是否打算这样做,但这样做是可行的。
I actually had to develop something similar for a school project. The idea was to generalize the notion of pipes to achieve something like this :
(loops are also possible)
In order to do this, my program did the following things:
In my case, since the processes called were also developed by me, I could just pass the pipes file descriptors as arguments to the child processes (--pipe-in .... --pipe-out ....), but since you are using existing programs based on stdin/stdout, you could use dup2() to "copy" the standard I/O pipes.
I do not know if this is how you plan on doing this, but it is doable that way.