How do I run a batch file from my Java Application?

后端 未结 11 1699
情书的邮戳
情书的邮戳 2020-11-22 00:42

In my Java application, I want to run a batch file that calls \"scons -Q implicit-deps-changed build\\file_load_type export\\file_load_type\"

It seems t

11条回答
  •  死守一世寂寞
    2020-11-22 01:21

    Runtime runtime = Runtime.getRuntime();
    try {
        Process p1 = runtime.exec("cmd /c start D:\\temp\\a.bat");
        InputStream is = p1.getInputStream();
        int i = 0;
        while( (i = is.read() ) != -1) {
            System.out.print((char)i);
        }
    } catch(IOException ioException) {
        System.out.println(ioException.getMessage() );
    }
    

提交回复
热议问题