1

I'm attempting to launch several batch files in their own windows using the Apache Commons Exec library, and although I'm able to launch them properly, I'm running into one small issue where the output from the JVMs being spawned are showing in the window for the original process. I need them to all display in their own separate windows, but despite using what I thought were the correct parameters, all the output dumps to the original console.

Here is how I am spawning the processes.

CommandLine cmd = new CommandLine("cmd");

cmd.addArgument("start");
cmd.addArgument("/MIN");
cmd.addArgument("/I");

cmd.addArgument("cmd.exe");
cmd.addArgument("/C");

cmd.addArgument(script);
cmd.addArgument(groupName);

Executor executor = new DefaultExecutor();
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

try {
    PumpStreamHandler psh = new PumpStreamHandler(new ExecOutputStream(LOG, Level.DEBUG), new ExecOutputStream(LOG, Level.ERROR));

    executor.setWatchdog(watchdog);
    executor.setExitValue(0);
    executor.setStreamHandler(psh);
    executor.execute(cmd, resultHandler);

    resultHandler.waitFor(5_000);
} catch(IOException io) {
    // handle IOException...
} catch(InterruptedException ie) {
    // handle InterruptedException...
}

Is there a parameter for the start command I'm missing to cause these to spawn in their own console windows? Or is there some other method of the executor class that needs to be called?

Darin Beaudreau
  • 375
  • 7
  • 30
  • Have you looked at the `Start` command usage/man page? i.e. `Start /?` – Compo Apr 20 '18 at 19:26
  • Yes, and my understanding was that /C will terminate after executing the command (realized this after posting, so I changed it to /K). Now that it's /K, it doesn't spawn any windows or output anything, but I can see the JVM process running, and I have no way to terminate it without task manager. – Darin Beaudreau Apr 20 '18 at 19:34
  • I would think you would need to launch `START` from `CMD.exe`. But I have no knowledge of how Java or apache commons works. – Squashman Apr 20 '18 at 20:18

0 Answers0