常规调用方式:(这个肯定会弹出cmd窗口)

实现代码如下:

Runtime.getRuntime().exec("cmd.exe   /C   start   D:\\test.bat");

解决不弹框只需要“start”后面加一个参数“/b”就行:
实现代码如下:

Runtime.getRuntime().exec("cmd.exe   /C   start   /b   D:\\test.bat");

实现代码如下:

Runtime rt = Runtime.getRuntime();
Process ps = null;
try {
   ps = rt.exec("cmd.exe /C start /b D:\\test.bat");
} catch (IOException e1) {
   e1.printStackTrace();
}
ps.waitFor();
int i = ps.exitValue();
if (i == 0) {
  System.out.println("执行完成.") ;
} else {
  System.out.println("执行失败.") ;
}

以上就是【解决Java调用BAT批处理不弹出cmd窗口的方法分析】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)

与本文相关的软件

发表我的评论

最新评论

  1. 暂无评论