[Tutor] Correct way to call an outside program?

Allen Fowler allen.fowler at yahoo.com
Thu Mar 13 19:39:49 CET 2008


Thank you for the help.  :)

----- Original Message ----

simplest way to run external commands ! 

import os 
cmd="/usr/bin/ssh 10.0.0.20 uptime"
os.popen(cmd)

my cmd is just an example, use any cmd you want & its output will be displayed to you.
hope this helps

[SNIP]



subprocess.Popen().communicate() will do it:

In [1]: import subprocess
In [7]: x=subprocess.Popen('ls', stdout=subprocess.PIPE,
stderr=subprocess.PIPE).communicate()
In [10]: print x[0]
....

If you just want stdout and stderr of the subprocess to go to stdout and
stderr of the calling process you can omit those arguments to Popen().






      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080313/2865ebcf/attachment.htm 


More information about the Tutor mailing list