Mind you, before this goes to prod please add error handling and logging. What happens when bar fails? What about baz? Now, please rewrite this so your team mates can maintain and extend. Yawn, I’ll wait for the PR.
Re:Advanced Bash-Scripting Guide (2014)
by aaaaaaaaaaab on Friday August 19, 2022 @05:04PM
(#32525879)
Gotcha, thanks for the feedback! We should also totally A/B test this! I'll make sure that this ties in with the quarterly OKRs, too! I hope I'll get promoted to E6 for that sweet 10% raise next cycle :fingers_crossed:
Nothing stops you from calling bash from Python to combine bash pipelines (onelines) but if you must use Python for some reason, to run `baz` for each line in `foo` & `bar` output:
from subprocess import Popen, PIPE, run
with Popen('foo', stdout=PIPE) as foo, Popen('bar', stdout=PIPE) as bar:
for f, b in zip(foo.stdout, bar.stdout):
run(['baz', f, b])
(there is a slight difference in behaviour)replace bash one-liner with python? No, thanks
replace 200+ bash script with multiple subroutines in python? yes
Python sucks for building processing pipelines.
How many lines of Python code would you need to implement this?
Mind you, `foo` and `bar` run in parallel.