Tuesday 12 February 2008

python run system command: os.exec.....

Python can call other program easily. Here are some ways:

import os

os.chdir('the path your program is in')
os.execv('WinProgram.exe',['argv[0]','other parameter']) # here the first one will not passed to the program!!!! And execv requires the arguments are in one list or turtle.
##os.execl('WinProgram.exe','argv[0]','other parameter')
##os.system('WinProgram.exe'+' '+'other parameter')

Here os.system just run the command, while execl and execv will stop current process and turn to another one, the rest codes will not run.

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter