I'm making a text editor in Java, and I want it to be able to run a Python file in the OS's command line. So on windows, I want the Python file to be run in cmd, and in Mac, Terminal, and so on.. I can already determine the operating system of the user, this isn't a problem. The problem is that I can't get it to run in the command line. Even if I try to make it only windows compatible and always run in cmd. I use this code to run the file, which I found from another question on stackoverflow. (I have been trying to find an answer for a while now)
ProcessBuilder builder = new ProcessBuilder(
"cmd.exe", "/c", cmd2Run.getText());
builder.redirectErrorStream(true);
Process p = builder.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while (true) {
line = r.readLine();
if (line == null) {
break;
}
System.out.println(line);
}
But, as I was expecting (because of the System.out.println...) it does run the Python file, but outputs it to the Java console. This would be fine, but then I thought "what if the user wants input?". So I realised I need to run the file in cmd. Is this possible? I wouldn't have thought it would be so difficult.