Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can running CMD from c# with a hidden CMD

Tags:

c#

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

like image 791
sari k Avatar asked Jan 24 '26 07:01

sari k


1 Answers

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;
    }

}
like image 184
David Hedlund Avatar answered Jan 26 '26 21:01

David Hedlund



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!