I tried this but it didin't work. My method to launch command prompt commands:
public static void executeCommand(String command, String path){
File folder = new File(path);
ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(folder.getAbsoluteFile());
pb.redirectErrorStream(true);
try{
pb.start();
}catch (IOException e){
e.printStackTrace();
}
}
`
and the code to call the methods:
executeCommand("javac "+str+".java", path);
executeCommand("java "+str, path);
But it's throwing an IOException. I was wondering if this was the wrong way to do it and how I can fix it. "str" is the .java file. The path is the path of the folder to run it in.