0

I am running a batch file through my Java class which starts up a server window popup. No code after the call to the bat file is reachable since the server continually runs so the code is stuck on the bat call statement. (I've tested with a bat file that closes automatically when finished, and code after that bat call is indeed reachable.)

Is there any way to call the bat file, and return execution to the Java class so it can keep executing the code below the call?

public void runBatchFile(String batLocation, String batName) throws IOException {
    ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "cd " + batLocation + " && " + batName);
    builder.redirectErrorStream(true);
    Process p = builder.start();
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while (true) {
        line = r.readLine();
        if (line == null) {
            break;
        }
        System.out.println(line);
    }
}
khelwood
  • 55,782
  • 14
  • 81
  • 108
displayName
  • 195
  • 2
  • 15

0 Answers0