[Tutor] Running external commands from Python

Luke Paireepinart rabidpoobear at gmail.com
Sat Jun 26 01:39:53 CEST 2010


Subprocess module is the preferred strategy when You want to communicate with the command you're running. If not, you can use os.system.

Sent from my iPhone

On Jun 25, 2010, at 5:46 PM, Randy Kao <randykao at gmail.com> wrote:

> Hi all,
> 
> I'm a newbie to Python (switching from Perl) and had a question about the best way to run external commands in Python.
> 
> In doing some reading I'm confused about which is the best way to accomplish this.
> 
> With Perl, the way I went about running commands was by opening a filehandle and parsing / manipulating the data.
> 
> i.e. open(XYZ, "ls -la *");
> 
> 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()
> 
> I might not be understanding when to use which of these correctly and was hoping for some feedback from this more experienced group.
> 
> Thanks in advance!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list