我正在尝试运行一个输出到命令框的 exe 程序。我正在重定向输出以显示在文本框中,但它似乎只在程序完成时显示整个结果。我希望它在执行时一次显示一行。
这是我的代码:
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
无论如何,根据 MSDN,在我看来这应该有效,但事实并非如此。