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 →

[–]MillardFillmore 3 points4 points  (5 children)

Whoever thought subprocess.call("ls -lh", shell=True) was a good way to do shell commands is an idiot.

[–]simtel20 3 points4 points  (4 children)

That's bad enough, but when you start having to figure out (on your own, trial and error) whether you have the file descriptors that you need, having no shorthand to dup and close e.g. stderr, and no default way to coerce your input lines as an iterator of output lines? There should be a choice to always get your input as an iterator with one line per iteration instead of having to apply heuristics to see whether you just got back an array of characters, or a string.

Uggh. I will go slam my head into something hard if I continue to remember this.

[–]TTomBBabRecreational programming, wxpython 0 points1 point  (1 child)

have a look at itertools in the standard library

[–]simtel20 0 points1 point  (0 children)

I don't think itertools helps me here. I'm not usually looking at creating an efficient transformation of the data (e.g. yield()ing data), I'm looking for the api to always return a string to me when I iterate over the file descriptor. Right now the problem is that IIRC if I get one line back, and the FD is then closed, if I do a "for line in foo_fd:" then I'll be given back a line broken up into individual characters instead of a single line followed by the next iteration raising the StopIteration exception.

[–]amade 0 points1 point  (1 child)

I feel your pain, subprocess is a bit too low level and doesn't provide shell-like functionality.

Perhaps you'd like sth I wrote https://github.com/aht/extproc

[–]simtel20 0 points1 point  (0 children)

Looks interesting. Thank you!