C# 执行Cmd窗口中的命令 [复制文件实例]

时间:2023-12-29 21:34:08
   /// <summary>
/// 复制文件夹
/// </summary>
/// <param name="sCmd"></param>
private void ExcuteXCopyCmd(string sCmd)
{
System.Diagnostics.Process proIP = new System.Diagnostics.Process();
proIP.StartInfo.FileName = "cmd.exe";
proIP.StartInfo.UseShellExecute = false;
proIP.StartInfo.RedirectStandardInput = true;
proIP.StartInfo.RedirectStandardOutput = true;
proIP.StartInfo.RedirectStandardError = true;
proIP.StartInfo.CreateNoWindow = true;
proIP.Start();
proIP.StandardInput.WriteLine(sCmd);
proIP.StandardInput.WriteLine("exit");
string strResult = proIP.StandardOutput.ReadToEnd();
//lstLog.Items.Insert(0, string.Format("【{0}】子目录批量复制命令结果:", strResult));
Log(string.Format("【{0}】子目录批量复制命令结果", strResult));
proIP.Close(); }