【发布时间】:2017-04-27 22:29:30
【问题描述】:
我正在通过 Process 类启动一个 exe,我注意到该 exe 的输出显示在我的应用程序的命令窗口中。 *注意 - 当我启动 exe 时,我确保没有打开一个窗口 - 因此,当我的应用程序运行时显示的唯一窗口是我的主应用程序 project.exe。
有没有办法阻止 exe 的输出显示在我的 project.exe 命令窗口中?这是我的代码:
Process process = new Process();
string exePath = System.IO.Path.Combine(workingDir, exeString);
process.StartInfo.FileName = exePath;
process.StartInfo.WorkingDirectory = workingDir;
process.StartInfo.Arguments = args;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.OutputDataReceived += (s, e) => Logger.LogInfo(e.Data);
process.Start();
process.BeginOutputReadLine();
process.WaitForExit();
我什至尝试将 RedirectStandardOutput 设置为 false :
process.StartInfo.RedirectStandardOutput = false;
并且输出仍然放置在命令窗口中。
【问题讨论】:
-
process.BeginOutputReadLine();进程.WaitForExit();应该在进程开始之后。即在 process.Start() 之后
-
我的错 - 这是一个错字 - 感谢您指出这一点。我会编辑帖子。
-
@loneshark99 现在测试它 - 但是你从哪里得到 Dump() ?那不是字符串类方法。
-
我尝试在 Linqpad 中进行测试。
标签: c# shell command-line process