Redirect Ping Output To A Textbox In The Form?

taffer

Newcomer
Joined
Feb 4, 2007
Messages
1
YES I WANTED TO REDIRECT THE PING COMMAND'S OUTPUT TO A TEXTBOX IN THE FORM.I WROTE THIS CODE BUT IT IS NOT WORKING.COULD U PLEASE HELP ME ON THIS

Visual Basic:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim p As New Process()
        Dim ps As New ProcessStartInfo
        p.StartInfo.FileName = "cmd.exe"
        Dim str As String
        str = "ping 10.21.19.1"

        p.StartInfo.Arguments = str


        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.Start()
      'Console.WriteLine(p.StandardOutput.ReadToEnd)
  TextBox2.AppendText(p.StandardOutput.ReadToEnd())
 
Last edited by a moderator:
/k switch or use ping.exe

When you wish to start cmd.exe to run another application, you must specify the /k switch, so your input arguments should be:

Visual Basic:
str = "/k ping 10.21.19.1"
p.StartInfo.Arguments = str

However, this raises the question of why bother launching cmd.exe just to then run ping? You may as well just execute ping.exe from the outset:

Visual Basic:
Dim p As New Process()
Dim ps As New ProcessStartInfo
Dim str As String

str = "10.21.19.1"
p.StartInfo.FileName = "ping.exe"
p.StartInfo.Arguments = str
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.Start()

TextBox2.AppendText(p.StandardOutput.ReadToEnd())

Good luck :cool:
 
Back
Top