Imagine that I'm starting my Java Compilation from a Command Prompt Window (say W0), where I have compiled the following piece of code.
public static void main(String... args) {
new ProcessBuilder("cmd", "/c", "start cmd.exe").inheritIO().start().waitFor();
System.out.println("Done!");
}
This will open one more Command Prompt Window (say W1), but yet the string "Done!" is printed in the previous window W0.
I have made the following attempt to get rid out of this.
public static void main(String... args) {
ProcessBuilder processBuilder0 = new ProcessBuilder("cmd", "/c", "start", "cmd.exe");
ProcessBuilder processBuilder1 = processBuilder0.inheritIO();
Process process = processBuilder1.start();
process.waitFor();
OutputStream os = process.getOutputStream();
System.setOut(new PrintStream(os));
System.out.println("Done!");
}
But now the string "Done!", is not getting printed in both W0 and W1, as the standard OutputStream has been changed to some 'UNKNOWN' stream.
System.setOut(new PrintStream(os));
I can set the OutputStream to some other user files, but the real problem is that I'm unable to transfer the control to another Command Prompt.
Kindly, help me to solve this problem.