1

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.

2 Answers 2

6

Try the following:

ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", "java", "-jar", "AnotherApp.jar");
Sign up to request clarification or add additional context in comments.

2 Comments

java.io.IOException: Cannot run program "start": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(Unknown Source)
Updated the answer, try this version, please.
1

Another alternative.

String cmd[]={"cmd", "/c", "start", "java", "-jar", "AnotherApp.jar"};

Runtime rt=Runtime.getRuntime();

Process p=rt.exec(cmd);

you can get output stream of p(that will be given to you as inputstream to read from) and print it to any console.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.