星期一, 11月 08, 2010

Python 使用 subprocess module 呼叫外部程式

# 當呼叫內建的指令,如 dir 時, Popen()裡的 shell 要設為 True
# stdout 可以設成檔案輸出, 如下:
fopen = open('hello.txt','w')
subprocess.Popen('dir',shell = True, stdout = fopen)
fopen.close()