call external .exe in python

simple way:

import os
pathname = "Untitled1.exe"
os.system(pathname)

with parameter

subprocess.check_call(["Untitled1.exe",'parameter1','parameter2'],stdout = fout)
例如:

import subprocess
result=[]
fout = open('result.txt','w')
for i in range(8,15):
    subprocess.check_call(["Untitled1.exe",str(i),'3'],stdout = fout)
    print i
fout.close()

fin = open('result.txt','r')
for line in fin:
    print line



另外:關於c/c++的main 函數參數傳遞規則見:

c語言main函數參數說明 http://www.cnblogs.com/viviwind/archive/2012/09/05/2671905.html

注意:argc不用傳,argv[0]是文件名,從argv[1]開始纔是參數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章