Re:Pure Bash Bible
by ThePadawan on Thursday September 19, 2019 @03:21AM
(#21014056)
You might like the python "sh" library [0]. It's not perfect, but it sure does remove the visual noise around subprocess.
> yeah sure subprocess.check_output()
It's deprecated and does something quite different.
> If you ever dealt with much perl you know how much more pleasant and easy launching processes was in that language - like shell.
I'm sure it is, but you're missing my point.
> If you want to use that as evidence that I'm a garbage developer go ahead
Well that escalated quickly.
> open(SRC, "output_generator|");
> open(WC, "|wc -l);
>
> And you do whatever you want with those filehandles.
Again python does roughly the same, just with more overhead: a trailing pipe is an "stdout=PIPE", an input is a "input=<whatever>", and you access / forward stdout explicitly:
src = Popen('output_generator', stdout=PIPE)
wc = Popen(['wc', '-l'], input=src.stdout)
And as the sibling notes, for shell replacements you can use the sh library to lower the syntactic overhead of popen.
In Perl you literally took the part of your shell pipeline, quoted it and opened it like any other file.
And you do whatever you want with those filehandles. It's been ages since I wrote any perl. I miss it.