1. 程式人生 > >C# 執行批處理檔案

C# 執行批處理檔案


//   System.Diagnostics.Process pr1 = System.Diagnostics.Process.Start("cmd", " /c ftpget.bat");
//   pr1.StartInfo.CreateNoWindow = true;
//   pr1.WaitForExit(); 
   System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");

   psi.UseShellExecute = false;

   psi.RedirectStandardOutput = true;

   //psi.RedirectStandardInput = true;

   psi.RedirectStandardError = true;

   psi.Arguments = "/c F://aa//ftpget.bat";

   psi.WorkingDirectory = "F://aa//";

   // Start the process

   System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);

   // Attach the output for reading

   System.IO.StreamReader sOut = proc.StandardOutput;

   proc.Close();

   // Read the sOut to a string.

   string results = sOut.ReadToEnd().Trim();

   sOut.Close();
   Console.WriteLine(results);