I’m trying to open a new console window in java and have a Console object referencing it. I know that the following code opens a console in windows,
Process p = Runtime.getRuntime().exec("cmd /c start cmd.exe");
p.waitFor();
Is there a way do Console cons = ... in conjunction with the above such that the console object is referencing the new one I just opened? Or am I completely going at this incorrectly and there is a better way?
You are misunderstanding what the
Consoleobject in Java represents. From the Javadoc:It represents the console device associated with a JVM process, and its also not garaunteed to exist. If you want to interact with a system console launched from a Java process, then you will need to do so via its input and output streams.