您的位置:首页 > 编程语言 > C#

C#调用CMD命令后显示命令后信息

2011-07-28 23:55 411 查看
private   void   button1_Click(object   sender,   EventArgs   e)
{
try
{
Process   p   =   new   Process();
p.StartInfo.FileName   =   "cmd.exe ";
p.StartInfo.UseShellExecute   =   false;
p.StartInfo.RedirectStandardInput   =   true;
p.StartInfo.RedirectStandardOutput   =   true;
p.StartInfo.RedirectStandardError   =   true;
p.StartInfo.CreateNoWindow   =   true;
p.Start();
p.StandardInput.WriteLine( "ping   172.16.1.1 ");
p.StandardInput.WriteLine( "exit ");
string   strRst   =   p.StandardOutput.ReadToEnd();
p.WaitForExit();
this.label1.Text   =   strRst;
}
catch   (Exception   err)
{
MessageBox.Show(err.Message);   //显示错误信息。
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: