C#中执行批处理文件(*.bat)的方法代码
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:staticvoidMain(string[]args){Processproc=null;try{stringtarge...
复制代码 代码如下:
static void Main(string[] args)
{
Process proc = null;
try
{
string targetDir = string.Format(@"D:adapterssetup");//this is where mybatch.bat lies
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "mybatch.bat";
proc.StartInfo.Arguments = string.Format("10");//this is argument
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occurred :{0},{1}", ex.Message,ex.StackTrace.ToString());
}
}
如果要运行时隐藏dos窗口,需使用下面的代码
复制代码 代码如下:
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;