C# 执行CMD命令

来源:互联网 发布:淘宝客返利是什么 编辑:程序博客网 时间:2024/04/30 06:19
  private static string ExcuteWinCmdStr(string cmdStr)        {            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(cmdStr);            p.StandardInput.WriteLine("exit");             return p.StandardOutput.ReadToEnd();                   }
private static string ExcuteWinCmdStr(string cmdStr){    Process process = new Process {        StartInfo = { FileName = "cmd.exe", UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }    };    process.Start();    process.StandardInput.WriteLine(cmdStr);    process.StandardInput.WriteLine("exit");    return process.StandardOutput.ReadToEnd();} 


0 0
原创粉丝点击