简体   繁体   English

如何执行命令替换,例如“ echo hi | tee>(gzip> / tmp / 1)> / tmp / 2”在铅锤中?

[英]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/2echo 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.

相关问题 如何gzip tmp文件夹中的文件 - how to gzip files in tmp folder 如何将 python 中带有特殊字符的字符串传递给 os.system。 (例如 python test.py |& tee output.txt) - How to pass a string with special chars in python to os.system. (E.g. python test.py |& tee output.txt) 如何在 discord.py 中的命令(例如 User: :send 1234 Bot?1234)后重新发送用户输入? - How do I resend user input after a command (e.g. User: !send 1234 Bot: 1234) in discord.py? 你如何在 Python 中用 numpy 做自然日志(例如“ln()”)? - How do you do natural logs (e.g. “ln()”) with numpy in Python? 如何导入时间的特定部分,例如 Python 中的小时或分钟? - How do I import specific parts of the time, e.g. hours or minutes in Python? 如何进行时间序列反向重采样,例如从最后一个数据日期开始的 5 个工作日? - How to do time series backward resampling e.g. 5 business days starting on the last data date? numpy 的就地操作(例如`+=`)如何工作? - How do numpy's in-place operations (e.g. `+=`) work? 如何在NLTK中使用书籍功能(例如concoordance)? - How do I use the book functions (e.g. concoordance) in NLTK? 你如何获得 python 包的 pydoc 可访问路径列表,例如 numpy 或 tensorflow? - How do you get a list of pydoc accessible paths for a python package, e.g. numpy or tensorflow? 如何使用 matplotlib 在图例中一次呈现多种语言(例如中文、西里尔文、英文)? - How do I render multiple languages (e.g. Chinese, cyrillic, english) at once in a legend using matplotlib?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM