How do I run a Console Application, capture the output and display it in a Literal?

吃可爱长大的小学妹 提交于 2019-11-29 02:46:47

I've done something very similar to your solution -- this is working fine for me:

ProcessStartInfo pInfo = new ProcessStartInfo("cmd.exe");
pInfo.FileName = exePath;
pInfo.WorkingDirectory = new FileInfo(exePath).DirectoryName;
pInfo.Arguments = args;
pInfo.CreateNoWindow = false;
pInfo.UseShellExecute = false;
pInfo.WindowStyle = ProcessWindowStyle.Normal;
pInfo.RedirectStandardOutput = true;
Process p = Process.Start(pInfo);
p.OutputDataReceived += p_OutputDataReceived;
p.BeginOutputReadLine();
p.WaitForExit();
// set status based on return code.
if (p.ExitCode == 0) this.Status = StatusEnum.CompletedSuccess;
   else this.Status = StatusEnum.CompletedFailure;

The interesting differences seem to be the use of WaitForExit(), and possibly the BeginOutputReadLine().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!