DSAPI.文件.CMD命令行進程代理,是用來和CMD.exe或指定exe進行輸出重定向的簡化使用工具,可隱藏或顯式地啟動一個cmd.exe,並將輸出流、輸入流和錯誤流重定向至代理,通過事件觸發方式與之交互。 相關代碼如下: ...
DSAPI.文件.CMD命令行進程代理,是用來和CMD.exe或指定exe進行輸出重定向的簡化使用工具,可隱藏或顯式地啟動一個cmd.exe,並將輸出流、輸入流和錯誤流重定向至代理,通過事件觸發方式與之交互。
相關代碼如下:
Private WithEvents CMD命令行 As New DSAPI.文件.CMD命令行進程代理 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click CMD命令行.啟動CMD命令行進程() End Sub Private Sub CMD命令行進程_有輸出內容(Sender As CMD命令行進程代理, 輸出內容 As String) Handles CMD命令行.有輸出內容, CMD命令行.有輸出報錯內容 Me.BeginInvoke(New SetText(AddressOf SetTextA), 輸出內容) End Sub Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing CMD命令行.退出進程() End Sub Private Delegate Sub SetText(S As String) Private Sub SetTextA(S As String) TextBox2.Text &= S TextBox2.SelectionStart = TextBox2.TextLength TextBox2.ScrollToCaret() End Sub Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown Select Case e.KeyValue Case Keys.Enter, Keys.Return CMD命令行.輸入(TextBox1.Text) TextBox1.Clear() Exit Sub End Select End Sub