如何在.net 中執行console命令private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load '創建一個新的進程對象 dim mycmdprocess as new process '注冊進程退出事件 'mycmdprocess.exited += new system.eventhandler(mycmdprocess_exited) addhandler mycmdprocess.exited, addressof mycmdprocess_exited mycmdprocess.startinfo.filename = "cmd" '要執行的命令 '將參數傳給要調用的應用程序 /c 執行字符串指定的命令然后終斷 ,調用dir,同時將結果輸出到應用程序文件夾下test.txt. mycmdprocess.startinfo.arguments = "/c dir >test.txt" mycmdprocess.startinfo.redirectstandardoutput = true mycmdprocess.startinfo.useshellexecute = false mycmdprocess.startinfo.createnowindow = true mycmdprocess.enableraisingevents = true mycmdprocess.start() console.read() end sub '進程退出時調用的方法private sub mycmdprocess_exited(byval sender as object, byval e as system.eventargs) try dim myfile as system.io.streamreader = new system.io.streamreader("test.txt") dim mystring as string = myfile.readtoend() myfile.close() messagebox.show(mystring) catch ex as exception messagebox.show(ex.message) end try end sub