3

How can running CMD from c# without to see the cmd windows?

sari k
  • 2,051
  • 6
  • 28
  • 34
  • Check out http://stackoverflow.com/questions/1096591/how-to-hide-cmd-window-while-running-a-batch-file - very similar to what you want to do – Jagmag Nov 08 '10 at 08:50

1 Answers1

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