Cannot get cmd.exe runtime result

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();

Team rmdir /s /q 123

I expect to get "The system cannot find the specified file" inside the variable outputcos "123" - this is the path to the file that does not exist. But output- an empty line. Why and how am I going to get a conclusion?

+3
source share
1 answer

The message you expect to see will be on StandardError, not StandardOutput.

+5
source

All Articles