FORM IN CMD
VNote
2017.07.10 10:24:08
*: Public Class Form1
Private psi As ProcessStartInfo
Private cmd As Process
Private Delegate Sub InvokeWithString(ByVal text As String)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox2.Clear()
If TextBox1.Text.Contains(" ") Then
psi = New ProcessStartInfo(TextBox1.Text.Split(" ")(0), TextBox1.Text.Split(" ")(1))
Else
psi = New ProcessStartInfo(TextBox1.Text$)
End If
Dim systemencoding As System.Text.Encoding = System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemencoding
.StandardErrorEncoding = systemencoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf AsyncDataReceived
AddHandler cmd.OutputDataReceived, AddressOf AsyncDataReceived
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
End Sub
Private Sub AsyncDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(New invokewithstring(AddressOf Sync_Output), e.Data)
End Sub
Private Sub Sync_Output(ByVal text As String)
TextBox2.AppendText(text & Environment.NewLine)
TextBox2.ScrollToCaret()
End Sub
End Class