Reputation: 3400
I am trying to launch a new cmd process, from that run a batch file to setup environments and from that run custom commands. Is this possible?
So far I have:
Process cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.Filename = <setup.cmd path>
cmd.StartInfo.CreateNoWindow = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.Start()
this successfully set up the environment but the cmd window immediately closes and i can't submit more commands.
Upvotes: 1
Views: 3476
Reputation: 216253
Simply add the ProcessStartInfo.Arguments and pass "/K" as value
Process cmd = new Process();
cmd.StartInfo.UseShellExecute = false;
cmd.StartInfo.FileName = "cmd.exe";
cmd.StartInfo.Arguments = "/K";
cmd.StartInfo.CreateNoWindow = false;
cmd.StartInfo.RedirectStandardInput = true;
cmd.Start();
Passing the argument /K
will force the command window to remain open
You can add also the name of your batch file after the /K
cmd.StartInfo.Arguments = "/K yourbatch.cmd args1 args2";
Upvotes: 2