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
? Or, to illustrate the illustrate the idea better, 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. Is there a way to avoid mkfifo
?
Note: I'm aware that the question is similar to "How to pipe many bash commands from python?". 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 withplumbum
This pipes the string "hi" to the
tee
function which writes it to "/tmp/2" and also copies it to stdout. Then, stdout is piped to gzip whose output is redirected to "/tmp/1".To achieve something similar with your other command (
find / | tee >( grep hi > /tmp/grepped ) > /tmp/nongrepped
)you can do: