将参数传递给cmd.exe的 [英] Passing an argument to cmd.exe

查看:2694
本文介绍了将参数传递给cmd.exe的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的C#程序ping通本地计算机。要,我用下面的code做到这一点。

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 = new System.Diagnostics.ProcessStartInfo();
proc.FileName = @"C:\windows\system32\cmd.exe";
proc.Arguments = @"""ping 10.2.2.125""";
System.Diagnostics.Process.Start(proc);

这将打开一个命令行窗口,但平不调用。这是什么原因?

This opens a command-line window, but ping is not invoked. What is the reason?

推荐答案

您需要包含/ C参数告诉CMD.EXE你的意思是做的:

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

(您的可以的通话PING.EXE直接的过程。有些时候,这是合适的,有时更容易调用 CMD 。 )

(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.exe的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆