Async ProcessStartInfo : Run cmd program to show in textbox just like cmd window in real time

StackOverflow https://stackoverflow.com/questions/16577112

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top