running a shell command from a python program

Thomas Guettler guettli at thomas-guettler.de
Wed Feb 23 10:29:04 EST 2005


Am Wed, 23 Feb 2005 07:00:31 -0800 schrieb Sandman:

> Hi,
>    I'm a newbie, so please be gentle :-)
> 
> How would I run a shell command in Python?
[cut]
> Is popen the answer? Also, where online would I get access to good
> sample code that I could peruse?

Yes, popen is the answer. I recommend popen4 because it avoids
deadlocks if there is output on stdout and stderr.

Example:
stdout, stdin = popen2.popen4("tidy -q -errors '%s'" % htmlfile)

HTH,
 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list