Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use more DOS commands in C#

Tags:

c#

process

dos

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
like image 327
FrewCen Avatar asked Aug 09 '11 16:08

FrewCen


People also ask

How do I use more command in DOS?

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.

Can you run 2 command prompts at once?

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.

How do I run multiple commands in one batch file?

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.


1 Answers

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();
like image 139
Brad Christie Avatar answered Sep 23 '22 03:09

Brad Christie