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')