python subprocess

来源:互联网 发布:阿里指数能看淘宝吗 编辑:程序博客网 时间:2024/05/22 08:09

import os

os.system('etc/program') #full path of the program

os.system('gedit')

#os.system('notpad.exe') #for windows

 

or:

os.popen()

 

os.popen() behaves similar to a file open(), the default is "r" for read, so for write to have to addd a "w". You can specify the buffer size in bytes or use the default of zero.

 

os.popen('program').write('whatever')

 

a = os.popen("cmd","w")

a.write("bla")

 

some discussion here: http://www.daniweb.com/forums/thread40790.html

see more here: http://docs.python.org/library/os.html

 

also: http://effbot.org/librarybook/os.htm

 

*******************

Use another method, subprocess, which is recommended. http://docs.python.org/library/subprocess.html

also http://www.oreillynet.com/onlamp/blog/2007/08/pymotw_subprocess_1.html

 

import subprocess# Command with shell expansion
subprocess.call('ls -l $HOME', shell=True)

subprocess.Popen('echo "Hello world!"', shell=True) #command through the shell.

 

 

 

This blog is also very great: http://jimmyg.org/blog/2009/working-with-python-subprocess.html

 

 

 

 

###################################################