0

I am starting a simple process using my c# code. I am able to open the cmd but not in the specified path and even the command is not executed, instead it shows The Handle is invalid error. It is done using simple winform application.

Below is my code:

        var process = new System.Diagnostics.Process();
        var startInfo = new System.Diagnostics.ProcessStartInfo
        {
            WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
            WorkingDirectory = @"D:\Work\Application",
            FileName = "cmd.exe",
            RedirectStandardInput = true,
            UseShellExecute = false
        };

        process.StartInfo = startInfo;
        process.Start();
        process.StandardInput.WriteLine("timeout /t 10");

It worked a day before but then it didnt work. I cant see what the problem is

Kishan Vikani
  • 105
  • 1
  • 9
  • 2
    Possible duplicate of [Run command line code programatically](https://stackoverflow.com/questions/13738168/run-command-line-code-programatically) – Capn Jack Aug 04 '17 at 19:03

1 Answers1

0

All you have to do is:

string cmdText;
cmdText = "/C timeout /t 10";
System.Diagnostics.Process.Start("CMD.exe", cmdText);
Bender Bending
  • 729
  • 8
  • 25