Search code examples
javawindowsjarconsoleprocessbuilder

Run java process in windows console from another java process


I am trying to start another Java process from my Java process. The problem is that I want Windows console to appear and AnotherApp to write to that console.

This Java snippet does start a new process, but console does not appear.

ProcessBuilder pb = new ProcessBuilder("cmd", "/k", "java", "-jar", "AnotherApp.jar");
pb.start();

If I run from Start - Run

cmd /k java -jar AnotherApp.jar

then a new console is created and java process is started.


Solution

  • Try the following:

    ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", "java", "-jar", "AnotherApp.jar");