taffer Posted February 4, 2007 Posted February 4, 2007 (edited) 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 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()) Edited February 4, 2007 by PlausiblyDamp Quote
MrPaul Posted February 4, 2007 Posted February 4, 2007 /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: 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: 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: Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.