Having problems with a console opened from visual basic

时间:2015-12-10 01:20:33

标签: vb.net cmd ping basic

Why does this result in a blank console popping up instead of a console with ping activated. When the console is closed and the output is displayed in textbox4.text it stops at "Pinging 192.168.1.254 with 100 bytes of data:" and dose not display the actual pings so im guessing that the console is not displaying at all and the ping stops before the first ping is sent.

what is going on

thanks for all help

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub STARTBUTTON_Click(sender As Object, e As EventArgs) Handles STARTBUTTON.Click

    Dim myprocess As New Process
    Dim StartInfo As New System.Diagnostics.ProcessStartInfo
    Dim cmdcode As String = "ping " + TextBox1.Text + " -t -l " + TextBox2.Text
    StartInfo.FileName = "cmd" 'starts cmd window
    StartInfo.RedirectStandardInput = True
    StartInfo.RedirectStandardOutput = True
    StartInfo.UseShellExecute = False 'required to redirect
    myprocess.StartInfo = StartInfo
    myprocess.Start()
    Dim SR As System.IO.StreamReader = myprocess.StandardOutput
    Dim SW As System.IO.StreamWriter = myprocess.StandardInput
    SW.WriteLine(cmdcode) 'the command you wish to run.....
    SW.WriteLine("exit") 'exits command prompt window
    TextBox4.Text = SR.ReadToEnd 'returns results of the command window
    SW.Close()
    SR.Close()

End Sub

End Class

0 个答案:

没有答案
相关问题