Reputation: 4945
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?
Upvotes: 3
Views: 1644
Reputation: 32576
The message you're expecting to see will be onStandardError
, not StandardOutput
.
Upvotes: 5