Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute command on cmd from C# [closed]

Tags:

c#

cmd

I want to run commands on the cmd from my C# app.

I tried:

string strCmdText = "ipconfig";
        System.Diagnostics.Process.Start("CMD.exe", strCmdText);  

result:

the cmd window pop but the command didn't do nothing.

why?

like image 670
user2257505 Avatar asked Apr 08 '13 12:04

user2257505


People also ask

How do I switch from C to D in cmd?

For instance, if you wanted to change the drive from C: to D:, you should type: d: … and then press Enter on your keyboard. To change the drive and the directory at the same time, use the cd command, followed by the /d switch.

Does cmd use C?

/C Carries out the command specified by the string and then terminates. You can get all the cmd command line switches by typing cmd /? .

How do you prompt in C?

Open Command Prompt in Windows 10Move the mouse pointer to the bottom-left corner of the screen and Right-click, or press Windows key + X. In the power user task menu, select Command Prompt (Admin) (Figure 8). This will open the Command Prompt window (Figure 9).


1 Answers

Use

System.Diagnostics.Process.Start("CMD.exe", "/C ipconfig");  

If you want to have cmd still opened use:

System.Diagnostics.Process.Start("CMD.exe", "/K ipconfig");  
like image 86
Piotr Stapp Avatar answered Oct 18 '22 15:10

Piotr Stapp