Frage

I am trying to run an exe program that outputs to the command box. I am redirecting the output to show in a textbox, but it seems to only show the entire results when the program is finished. I want it to display one line at a time as it executes.

THIS IS MY CODE:

Dim startInfo As ProcessStartInfo = New ProcessStartInfo(SomeDOScmd.exe)
startInfo.Arguments = some args
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = False
startInfo.ErrorDialog = False
startInfo.RedirectStandardOutput = True
Dim pr As Process = Process.Start(startInfo)
pr.BeginOutputReadLine()    
AddHandler pr.OutputDataReceived, AddressOf ShowOutput
pr.WaitForExit()
pr.Close()
pr.Dispose()

Private Sub ShowOutput(sendingProcess As Object, _
           outLine As DataReceivedEventArgs)
   txtShow.text += outLine.Data
End Sub  

Seems to me this should work, according to MSDN anyway, but it doesn't.

War es hilfreich?

Lösung

Rather than locating it to the textbox, loop to the number of lines and save each line in a string and send that string to the application you want to send to.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top