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")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章