What is the difference between all os.popen () methods?

I looked at the Python documentation and saw that there are 4-5 different versions of popen (), for example. os.popen (), os.popen2 (), etc.

Besides the fact that some of them include stderr and others do not, what are the differences between them and when will you use them? The documentation did not really explain this very well.

+7
python subprocess popen
source share
3 answers

I would recommend using the subprocess module, which has all the functions that these functions have, and much more.

+14
source share

Jason is right. To summarize, to make it easier to see:

  • os.popen () → stdout
  • os.popen2 () → (stdin, stdout)
  • os.popen3 () → (stdin, stdout, stderr)
  • os.popen4 () → (stdin, stdout_and_stderr)
+13
source share

popen2 does not write a standard error, popen3 makes a standard error and gives it a unique file descriptor. Finally, popen4 captures the standard error, but includes it in the same file object as the standard output.

+9
source share

All Articles