1. 程式人生 > >c#運行批處理文件

c#運行批處理文件

literal cts ring file run reat col tst out

主要的方法就是運用process類,它可以運行exe文件,cmd等的進程,在這裏我是用來運行我的.bat文件,以下是我在一個項目中使用到的方法:

//name bat文件名,path bat路徑

public static boolean RunBat(string name,string path)

{

  Process pro =new Process();

  ProcessStartInfo pro_s =new ProcessStartInfo();

  pro_s.FileName=name;

  pro_s.WorkingDirectory=path;

  pro_s.Arguments="10";//??

  pro_s.UseShellExecute=false; //

  pro_s.CreateNoWindow=false;

  pro_s.RedirectStandardOutput = true;

  ppro_sro.StartInfo.RedirectStandardError = true;

  pro.StartInfo=pro_s;

  pro.Start();

  pro.WaitForExit();

  return true; 

}

c#運行批處理文件