IronPython調用C#啓動外部進程

IronPython調用C#啓動外部進程

import clr  
clr.AddReference("System")
import System

#不能像下面這樣用
#clr.AddReference("System.Diagnostics")#這一行就出錯

#事件回調
def on_exit(*arg):
    print "exit"    

def callProcess(**arg):
    app = System.Diagnostics.Process()
    app.StartInfo.FileName = arg["appName"]
    if arg.has_key("args"):
        app.StartInfo.Arguments = arg["args"]
    #支持事件
    app.EnableRaisingEvents = True
    #添加事件處理
    app.Exited += on_exit
    app.Start()
    app.WaitForExit()
    print "end"


if __name__ == "__main__":
    callProcess(appName = "notepad.exe")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章