3

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 1
    You cannot fix this. Once you redirect output, cmd.exe (like any C/C++ program) switches to buffered output. The prompt is stuck in the buffer, it won't come out until you force it generate a new line. – Hans Passant May 16 '13 at 00:35
  • What happens if you try something like this: "txtShow.Refresh" or "Application.DoEvents" after your line "txtShow.text += outLine.Data"? – Steve Sep 24 '13 at 16:32

1 Answers1

1

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.

Afnan Makhdoom
  • 654
  • 1
  • 8
  • 20
  • Not sure I understand what you are saying. By using +=outline Data I am essentially looping through all the responses and making a long string as you said. – Tony Springs Oct 19 '13 at 16:20