python調用windows的exe可執行程序

#傳參調用exe程序(解決相對路徑,以爲路徑問題),等待exe進程結束,此程序才結束。 windows

# -*- coding: utf-8-*- 進程

import os, os.path, sys
import win32process, win32event utf-8

exe_path = sys.argv[1]
exe_file = sys.argv[2] it

#os.chdir(exe_path) io

try :
        handle = win32process.CreateProcess(os.path.join(exe_path, exe_file),
                '', None, None, 0,
                win32process.CREATE_NO_WINDOW, 
                None , 
                exe_path,
                win32process.STARTUPINFO())
        running = True        
except Exception, e:
        print "Create Error!"
        handle = None
        running = False event

while running :
        rc = win32event.WaitForSingleObject(handle[0], 1000)
        if rc == win32event.WAIT_OBJECT_0:
                running = False
#end while
print "GoodBye" import

 

#須要用的模塊:pywin32-214.win32-py2.5.exe  coding

把改程序作成exe程序,就能夠任何地方調用了(windows系統下)。 file

相關文章
相關標籤/搜索