如何在.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