C#: 执行批处理文件(*.bat)的方法

static void Main(string[] args)
{
    Process proc = null;
    try
    {                
        proc = new Process();
        proc.StartInfo.FileName = @"D:\adapters\setup\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;

posted on 2017-05-19 11:23  邬兴亮  阅读(368)  评论(0编辑  收藏  举报

导航