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

1

1 Answer 1

0

All you have to do is:

string cmdText;
cmdText = "/C timeout /t 10";
System.Diagnostics.Process.Start("CMD.exe", cmdText);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.