faqts : Computers : Programming : Languages : Python : Common Problems

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

50 of 54 people (93%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I envoke an external program from a python script

Jun 4th, 2003 04:22
Xcrash, Sam G,


This can be done a few ways, but the simplest method (and probably the 
only one you need right now) is the system function of the os module.
The following imports the os module and executes the command ls -la 
using the system function;
import os
os.system('ls -la')
It's also possible to use the popen functions from the os module, and 
the getoutput function from the commands module if you need to grab the 
external prog's feedback;
import os
x = os.popen('ls -la').read()
print x
import commands
x = commands.getoutput('ls -la')