Hi all,
I want to redirect the console output in real time to a textbox. And if any standard error arrives or Process completed than i have to give one msgbox stating that process completed.Is there any method avalible.Presently I have this code.But it is not working properly

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.TextBox1.Text = String.Empty
        Dim clsProcess As New System.Diagnostics.Process()
        clsProcess.StartInfo.UseShellExecute = False
        clsProcess.StartInfo.RedirectStandardOutput = True
        clsProcess.StartInfo.RedirectStandardError = True
        clsProcess.StartInfo.FileName = "cmd dir/s"
        clsProcess.StartInfo.CreateNoWindow = True
        clsProcess.Start()
        While (clsProcess.HasExited = False)
            Dim sLine As String = clsProcess.StandardOutput.ReadLine
            If (Not String.IsNullOrEmpty(sLine)) Then
                Me.TextBox1.Text &= sLine & vbCrLf
            End If
            Application.DoEvents()
        End While
        Me.TextBox1.Text += "Completed"
    End Sub

Thanks in Advance
Dana

Hi

Your code is almost there. All that is required is to break apart the filename and add arguments. See below

p

Dim clsProcess As New System.Diagnostics.Process()
clsProcess.StartInfo.UseShellExecute = False
clsProcess.StartInfo.RedirectStandardOutput = True
clsProcess.StartInfo.RedirectStandardError = True
clsProcess.StartInfo.FileName = "cmd.exe"
clsProcess.StartInfo.Arguments = "dir /s"
clsProcess.StartInfo.CreateNoWindow = True
clsProcess.Start()
While (clsProcess.HasExited = False)
Dim sLine As String = clsProcess.StandardOutput.ReadLine
If (Not String.IsNullOrEmpty(sLine)) Then

End If
Me.TextBox1.Text &= sLine & vbCrLf

Application.DoEvents()
End While
Me.TextBox1.Text += "Completed"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.