日期:2014-05-17 浏览次数:20880 次
private void button1_Click(object sender, EventArgs e)
{
string strCmd = this.txbCmd.Text; //获取命令行
string strCmdResult = InvokeCmd(strCmd);
rtbCmdResult.Text = strCmdResult; //输出到rtbCmdResult控件中
//MessageBox.Show(strCmdResult);
}
private static string InvokeCmd(string cmdArgs)
{
string Tstr = "";
System.Diagnostics.Process p = new System.Diagnostics.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(cmdArgs);
p.StandardInput.WriteLine("exit");
Tstr = p.StandardOutput.ReadToEnd();
p.Close();
return Tstr;
}