无法从 cmd.exe 执行获取输出
代码如下:
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
是一个空字符串。为什么以及如何获取输出?
The code is as follows:
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();
The command is rmdir /s /q 123
I expect to get "The system cannot find the file specified" inside the variable output
because "123" is a file path that doesn't exist. But output
is an empty string. Why and how should I go about getting the output?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您期望看到的消息将出现在
StandardError
上,而不是StandardOutput
上。The message you're expecting to see will be on
StandardError
, notStandardOutput
.