there is 2 textbox and 1 button
button1 = start cmd process
textbox1 = type command that you want to run it on cmd
textbox2 = live results of cmd process
in this case i replace textbox1 to "ping www.google.com" & "ping www.facebook.com"
the problem is.. result is not coming untill cmd is close
cmd is not automatic close.. i have to close it by myself
this is my code
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Threading
Imports System.Windows
Public Class Form1
Private Results As String
Private Delegate Sub delUpdate()
Private Finished As New delUpdate(AddressOf UpdateText)
Dim myprocess As New Process
Dim StartInfo As New System.Diagnostics.ProcessStartInfo
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
StartInfo.FileName = "cmd"
StartInfo.RedirectStandardInput = True
StartInfo.RedirectStandardOutput = True
StartInfo.UseShellExecute = False
StartInfo.CreateNoWindow = False
myprocess.StartInfo = StartInfo
myprocess.Start()
Dim CMDThread As New Threading.Thread(AddressOf CMDAutomate)
CMDThread.Start()
myprocess.StandardInput.WriteLine("ping www.google.com")
myprocess.StandardInput.WriteLine("ping www.facebook.com")
End Sub
Private Sub CMDAutomate()
On Error Resume Next
While myprocess.StandardOutput.EndOfStream = False
Results = myprocess.StandardOutput.ReadToEnd.ToString()
Invoke(Finished)
End While
End Sub
Private Sub UpdateText()
TextBox2.AppendText(System.Environment.NewLine() & Results)
TextBox2.ScrollToCaret()
End Sub
End Class