tags:

views:

174

answers:

3

Within a python script, I want to issue a command. In perl, I could define a command, save it as a variable (here, $cmd) then type system($cmd) and then the command is executed.

How can i do that in python?

+6  A: 

You can use os.system(), but prefer subprocess instead.

Ignacio Vazquez-Abrams
+1  A: 

Another good choice is "commands" module: http://docs.python.org/library/commands.html.

Aleksa
A: 

you can use os.system(), or the newer subprocess module. Other possible alternatives (for older Python versions) include these. (eg os.spawn*,os.popen*,etc)

Lastly, try using Python's modules to do operating system stuff instead of calling external commands if possible, unless its a third party tool you are executing and Python doesn't have the api.

ghostdog74