[英]How to do command substitution, e.g. “echo hi | tee >( gzip > /tmp/1 ) > /tmp/2” in plumbum?
I need to figure out how to call pipe substitution in plumbum. 我需要弄清楚如何在铅锤中调用管道替换。 Specifically, how to construct chains such as
echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
具体来说,如何构造诸如
echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
链echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
? echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
吗? Or, to illustrate the illustrate the idea better, find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
或者,为了更好地说明这个想法,请
find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
? find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
吗? I need this kind of approach because the equivalent of find /
that I'm going to use is very expensive to run and I can't save it on disk, so I need to apply two different filters in parallel. 我需要这种方法,因为要使用的等效
find /
运行非常昂贵,而且我无法将其保存在磁盘上,因此我需要并行应用两个不同的过滤器。 Is there a way to avoid mkfifo
? 有办法避免
mkfifo
吗?
Note: I'm aware that the question is similar to " How to pipe many bash commands from python? ". 注意:我知道问题类似于“ 如何从python传递许多bash命令? ”。 The difference, though, is that I'm asking specifically about plumbum and an attempt to write a plumbum-related answer there is flawed, as described in its comments.
但是,不同之处在于,我要特别询问铅问题,并且在那里写与铅有关的答案是有缺陷的,正如其评论中所述。
To replicate the command in the title of the question ( echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
), you can do the following with plumbum
要在问题的标题中复制命令(
echo hi | tee >( gzip > /tmp/1 ) > /tmp/2
),可以对plumbum
执行以下操作
from plumbum.cmd import echo, tee, gzip
(echo["hi"] | tee["/tmp/2"] | gzip > "/tmp/1")()
This pipes the string "hi" to the tee
function which writes it to "/tmp/2" and also copies it to stdout. 这会将字符串“ hi”输送到
tee
函数,该函数将其写入“ / tmp / 2”并将其复制到stdout。 Then, stdout is piped to gzip whose output is redirected to "/tmp/1". 然后,将stdout通过管道传输到gzip,其输出将重定向到“ / tmp / 1”。
To achieve something similar with your other command ( find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
) 要实现与您其他命令相似的功能(请
find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
)
you can do: 你可以做:
from plumbum.cmd import find, grep, tee
(find["/"] | tee["/tmp/nongrepped"] | grep["hi"] > "/tmp/grepped")()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.