C#中执行批处理文件(*.bat)的方法代码
程序员文章站
2023-12-01 13:24:10
复制代码 代码如下:static void main(string[] args){ process proc = null; ...
复制代码 代码如下:
static void main(string[] args)
{
process proc = null;
try
{
string targetdir = string.format(@"d:\adapters\setup");//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;
下一篇: 微信公众平台忘记登陆密码了怎么办