Reputation: 5089
I was looking at the Python documentation and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc.
Apart from the fact that some include stderr while others don't, what are the differences between them and when would you use each one? The documentation didn't really explain it very well.
Upvotes: 7
Views: 4979
Reputation: 1115
I would recommend to use the subprocess
module which has all the features that these functions have and more.
Upvotes: 13
Reputation: 375584
Jason has it right. To summarize in a way that's easier to see:
Upvotes: 16
Reputation: 78353
popen2 doesn't capture standard error, popen3 does capture standard error and gives a unique file handle for it. Finally, popen4 captures standard error but includes it in the same file object as standard output.
Upvotes: 10