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); //显示错误信息。
}
}
C#调用CMD命令后显示命令后信息
最新推荐文章于 2022-11-13 08:00:00 发布