日期:2014-05-17 浏览次数:21175 次
string commandStr=文本框1文本
Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/C " + "cmd.exe /c " + commandStr;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
try
{
process.Start();
文本框2文本 = process.StandardOutput.ReadToEnd();
process.WaitForExit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
process.Close();
process.Dispose();
}