无法从cmd.exe执行输出

时间:2011-06-02 05:51:18

标签: c# process cmd

代码如下:

ProcessStartInfo startInfo = new ProcessStartInfo("cmd", "/c" + command);
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.Arguments = arguments;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;

Process process = Process.start(startInfo);
StreamReader srOutput = process.StandardOutput;
string output = srOutput.ReadToEnd();

命令为rmdir /s /q 123

我希望在变量output内得到“系统无法找到指定的文件”,因为“123”是不存在的文件路径。但是output是一个空字符串。为什么以及如何获得输出?

1 个答案:

答案 0 :(得分:5)

您希望看到的消息将显示在StandardError上,而不是StandardOutput

相关问题