我尝试了3-4个版本,但没有一个对我有用。

Process proc = new Process();
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.RedirectStandardError = true;
StartInfo.RedirectStandardOutput = true;
StartInfo.FileName = path + "calculate.exe";
StartInfo.Arguments = input;
StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = true;

proc.StartInfo = StartInfo;

proc.Start();

proc.WaitForExit();

string output = proc.StandardOutput.ReadToEnd();

MessageBox.Show(output);


我得到一个空的MessageBox,为什么有任何想法?当我在WaitForExit处添加断点时,StandardOutput表示它没有被重定向或该过程尚未开始。

最佳答案

您需要设置RedirectStandardOutput,而不是RedirectStandardError
(另外,请确保该过程确实在写标准输出而不是标准错误)

关于c# - 无法从流程重定向标准输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17817036/

10-15 22:43