Mira esto, haz un pipe:
Public Class Form1
Private Results As String
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Dim button_click As Integer = 0
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
Private Sub UpdateText()
' txtResults.Text = Results
txtCommand.Clear()
txtResults.AppendText(System.Environment.NewLine() & Results)
txtResults.ScrollToCaret()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If button_click = 0 Then
opencmd()
button_click += 1
End If
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
End Sub
Private Sub opencmd()
StartInfo.FileName = "cmd" 'starts cmd window
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False 'required to redirect
StartInfo.CreateNoWindow = True 'creates no cmd window
myprocess.StartInfo = StartInfo
myprocess.Start()
End Sub
Private Sub CMDAutomate()
'Dim SR As System.IO.StreamReader = myprocess.StandardOutput
'Dim SW As System.IO.StreamWriter = myprocess.StandardInput
myprocess.StandardInput.WriteLine(txtCommand.Text) 'the command you wish to run.....
myprocess.StandardInput.WriteLine(System.Environment.NewLine())
' SW.WriteLine("exit") 'exits command prompt window
While myprocess.StandardOutput.EndOfStream = False
Results = myprocess.StandardOutput.ReadLine()
Invoke(Finished)
End While
'Results = SR.ReadToEnd 'returns results of the command window
'SW.Close()
'SR.Close()
'invokes Finished delegate, which updates textbox with the results text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
opencmd()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Application.ExitThread()
Application.Exit()
End
End Sub
End Class