Passing an argument to cmd.exe

public void ExecuteCommand(String command)
{
   Process p = new Process();
   ProcessStartInfo startInfo = new ProcessStartInfo();
   startInfo.FileName = "cmd.exe";
   startInfo.Arguments = @"/c " + command; // cmd.exe spesific implementation
   p.StartInfo = startInfo;
   p.Start();
}

Usage: ExecuteCommand(@"ping google.com -t");


You need to include the "/c" argument to tell cmd.exe what you mean it to do:

proc.Arguments = "/c ping 10.2.2.125";

(You could call ping.exe directly of course. There are times when that's appropriate, and times when it's easier to call cmd.)


cmd /C 

or

cmd /K

Probably /C because /K does not terminate right away

Tags:

C#

.Net