1

I was working on a project which needs to run two cmd commands on C#, I looked up on how to do it but nothing worked for me, and everyone was giving the solution to execute only one cmd command.

I would like to execute one command when the user clicks a button, then another one right after, without quitting the cmd, and if possible to hide the cmd window.

My goal would be to execute the 2 following commands in the cmd, to run a Run.bat file:

cd C:\users\user\documents\file
Run.bat

Thanks.

2
  • why not write a batch file that executes both for you? Then you just call the one bat file. Commented Jul 1, 2020 at 19:38
  • 1
    Perhaps this will help. You can run multiple commands separated by &&. And please do show the work you have done in running one command at least. See this to find code on how to execute from c#. Commented Jul 1, 2020 at 19:40

1 Answer 1

2

You can directly call "C:\users\user\documents\file\Run.bat" and set the working directory as well as the shell execute flag :

string path = @"C:\users\user\documents\file\";
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = path + "Run.bat";
process.StartInfo.WorkingDirectory = path;
process.StartInfo.UseShellExecute = true;
process.Start();
//process.WaitForExit();
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.