Passing an argument to cmd.exe

前端 未结 5 1598
春和景丽
春和景丽 2020-12-01 20:47

I am attempting to ping a local computer from my C# program. To accomplish this, I\'m using the following code.

System.Diagnostics.ProcessStartInfo proc = ne         


        
5条回答
  •  渐次进展
    2020-12-01 21:32

    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");

提交回复
热议问题