April 11th, 2013, 03:39 AM
Programatically use cmd.exe
1- I want to run a series of commands on cmd.exe from c#.
2- I need to open only one window of cmd
3- I need to keep the cmd window open through the execution and after the completion.
4- I need to display the commands executed as well as the output of the commands.
So basically i want to open and use the cmd.exe just like a manual user would.
I tried some methods, non could do all the 4 items above.
Below code works but does not display the commands/outputs and terminates after completion.
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
info.RedirectStandardInput = true;
info.UseShellExecute = false;
info.CreateNoWindow = false;
info.Arguments = "/k";
p.StartInfo = info;
using (StreamWriter sw = p.StandardInput)
sw.WriteLine("connect -r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123");
Click Here to Expand Forum to Full Width