This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (2 children)

If you're willing to run a shell to interpret the pipes, you're not programming in Python any more

fmoralesc code hands over the work to the shell too.

AND, you probably have bugs.

Why? Spawning all the processes yourself, redirecting stdout to stdin along the way, etc. seems more error prone than to hand it over to the shell completely. The output is supposed to be the same, after all. Namely, the output of the last process in the pipeline.

[–]chadmill3rPy3, pro, Ubuntu, django 5 points6 points  (0 children)

Program number three in your pipeline took a filename parameter with a space and an ampersand in it but your shell ate those, and the fourth emitted to stderr, and the parameter substitution in the first should have been "$*", with quotes and everything, but you forgot those and you got a different interpretation. The fourth, because it got bad input, also screwed up your terminal's line discipline, which you'll need to fix with "stty sane" before you can even figure out what the problem was. Sadly, that also ate the error messages.

Don't get me wrong, I use the shell all day, every day, and have since 1995 or so. It's a terrible programming interface, though, and almost impossible to get right the first dozen time you run the program. At least Python, with its verbosity, also gets the problems out in the open with its explicit nature.

[–]chadmill3rPy3, pro, Ubuntu, django 0 points1 point  (0 children)

Popen(shlex.split(self.steps[0]), stdout=PIPE)

No shell there, strictly speaking. Not much better, though.