[Tutor] Running external commands from Python

Alan Gauld alan.gauld at btinternet.com
Sat Jun 26 10:35:14 CEST 2010

"Randy Kao" <randykao at gmail.com> wrote

> In trying to do this in Python, I think I've read a couple ways to 
> do this.
> through: os.popen, os.popen2, os.popen3, os.system, 
> commands.getoutput()

This is historically one of the things that Python has had trouble 
The things you list have all been introduced over the years to 
how it works. The current "official" method is to use the subprocess
module which replaces all of the above. But it does so by adding
some complexity and to really master it requires a fair bit of study
and experimentation. The good news is that the complexity offers
a very rich set of tools that can do pretty much anything tyou could
imagine in the way of working with external programs.

The "Working with the OS" topic in my tutorioal(V2 only) has some
basic examples of both the older techniques and the subprocess


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list