常规调用方式:(这个肯定会弹出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("执行失败." ) ;
- }