当前位置:编程学习 > C#/ASP.NET >>

如何在.net 中执行console命令

如何在.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")
补充:asp.net教程,基础入门
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,