I have about 7 commands in DOS and I want to run them in my C# program. Can I do:
System.Diagnostics.Process.Start("cmd.exe", "my more commands here");
? EDIT: I'm making small app what will run g++. Is this now correct?:
System.Diagnostics.Process.Start("cmd.exe", "/k cd C:\\Alps\\compiler\\ /k g++ C:\\Alps\\" + project_name + "\\Debug\\Main.cpp");
Command for compiling:
g++ -c C:\Alps\here_is_projectname\Debug\Main.cpp -o main.o
The more command displays the first screen of information from Clients. new, and you can press the SPACEBAR to see the next screen of information. The more prompt asks you for the number of lines to display, as follows: -- More -- Lines: . Type the number of lines to display, and then press ENTER.
Click Start, type cmd, and press Enter to open a command prompt window. In the Windows taskbar, right-click the command prompt window icon and select Command Prompt. A second command prompt window is opened.
Try using the conditional execution & or the && between each command either with a copy and paste into the cmd.exe window or in a batch file. Additionally, you can use the double pipe || symbols instead to only run the next command if the previous command failed.
cmd.exe /k <command>
cmd.exe /c <command>
Are both valid.
/k
will execute the command and leave you with an empty prompt (probably less desirable in your application if you just want to execute for feedback.)/c
will execute the command and close the window when it has completed.If you're looking to execute a command from a specific directory, you can do:
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe");
p.StartInfo.Arguments = String.Format(@"/c g++ ""C:\Alps\{0}\Debug\Main.cpp""", project_name);
p.StartInfo.WorkingDirectory = @"C:\Alps\compiler";
p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = false;
p.Start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With