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

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

Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top