os.popen--which one to use?

K

Kevin Walzer

I'm confused by the number of variations on "popen" that Python offers.

I'm using os.popen in my programs without difficulty. Is this wrong?
Should I be using popen 2, popen3, etc.? I'm not clear on what the
advantages of popen2, 3 etc. are: they seem a lot more complicated.
 
R

Robert Kern

Kevin said:
I'm confused by the number of variations on "popen" that Python offers.

I'm using os.popen in my programs without difficulty. Is this wrong?
Should I be using popen 2, popen3, etc.? I'm not clear on what the
advantages of popen2, 3 etc. are: they seem a lot more complicated.

Use the subprocess module, instead. It makes all of the popen functions more or
less obsolete (it used to be called popen5 before it got moved into the standard
library).

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
D

danmcleran

I'm confused by the number of variations on "popen" that Python offers.

I'm using os.popen in my programs without difficulty. Is this wrong?
Should I be using popen 2, popen3, etc.? I'm not clear on what the
advantages of popen2, 3 etc. are: they seem a lot more complicated.


Check out subprocess. It's meant to be a replacement for all of the
above.
 
K

kyosohma

I'm confused by the number of variations on "popen" that Python offers.

I'm using os.popen in my programs without difficulty. Is this wrong?
Should I be using popen 2, popen3, etc.? I'm not clear on what the
advantages of popen2, 3 etc. are: they seem a lot more complicated.

There's nothing wrong with using os.popen. Some of them are Unix
specific though. And that module's functionality along with os.system,
os.spawn and commands have all be integrated into the subprocess
module, which I think is much less confusing. The only places I've
seen a fairly coherent run-down of the os.popen modules is the "Python
in a Nutshell" book and maybe (I can't remember for sure) "Core Python
Programming".

See http://pydoc.org/2.4.1/subprocess.html for more info on the
subprocess module.

Mike
 
K

Kevin Walzer

Check out subprocess. It's meant to be a replacement for all of the
above.

OK, I've done this. What is the benefit of subprocess? Improved
performance? It doesn't seem that way--in fact, os.popen has a
non-blocking mode, which subprocess seems to lack.
 
R

Robert Kern

Kevin said:
OK, I've done this. What is the benefit of subprocess?

Code that will work on most platforms and into the Python 3.0, when the popen*
zoo will disappear in favor of subprocess.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top