How can running CMD from c# without to see the cmd windows?
Asked
Active
Viewed 7,270 times
1 Answers
9
In ProcessStartInfo
there's a parameter called CreateNoWindow
public static string ExecuteCommand(string command) {
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + command)
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
using (Process proc = new Process())
{
proc.StartInfo = procStartInfo;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
if (string.IsNullOrEmpty(output))
output = proc.StandardError.ReadToEnd();
return output;
}
}

David Hedlund
- 128,221
- 31
- 203
- 222