[VB.NET] Live bat streaming output
Inviato: 05/10/2013, 18:18
- Codice: Seleziona tutto
Imports system.io
Imports Microsoft.VisualBasic.ControlChars
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p = New Process
p.StartInfo.FileName = "Test.bat"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
AddHandler p.OutputDataReceived, AddressOf p_OutputDataReceived
p.Start()
p.BeginOutputReadLine()
End Sub
Public Sub p_OutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
UpdateTextBox(e.Data)
End Sub
Delegate Sub SetTextCallback(ByVal [text] As String)
Private Sub UpdateTextBox(ByVal text As String)
If Me.RichTextBox1.InvokeRequired Then
Dim d As New SetTextCallback(AddressOf UpdateTextBox)
Me.Invoke(d, New Object() {text})
Else
If RichTextBox1.Text = Nothing Then RichTextBox1.Text = text Else RichTextBox1.AppendText(vbNewLine & text)
End If
End Sub
End Class