java执行bat文件

来源:互联网 发布:淘宝店铺如何上传宝贝 编辑:程序博客网 时间:2024/04/29 20:30
public static void main(String[] args) {
        String batName = "C:/Users/fl/Desktop/test.bat";
        Runtime rt = Runtime.getRuntime();
        Process ps = null;
        try {
           ps = rt.exec("cmd.exe /C start /b " + batName);
           ps.waitFor();
        } catch (IOException e1) {
           e1.printStackTrace();
        } catch (InterruptedException e) {
e.printStackTrace();
}
        int i = ps.exitValue();
        if (i == 0) {
          System.out.println("执行完成.") ;
        } else {
          System.out.println("执行失败.") ;
        }
    }
0 0
原创粉丝点击