I've got an external executable program which I want to run from within my java program. While it is running, I need a way to get what the .exe is outputting, and also a way to then send input back to the .exe. This is what I've conjured up so far:
public int run(){
String cmdRun = "cmd C:\\Meister\\Student\\bin\\Student.exe";
int returnCode = 1;
try {
Process p = Runtime.getRuntime().exec(cmdRun); // makes appropriate system call
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String s = null;
// read any info from the attempted command
while ((s = stdError.readLine()) != null){ returnCode = -1; break; }
while ((s = stdInput.readLine()) != null){ System.out.println(s); }
System.out.println("Finished with exit code " + p.waitFor());
} catch (Exception e) {
e.printStackTrace();
}
return returnCode;
}
How should I properly RUN (1) the program, GET (2) the program output, and then SEND (3) input to the program when necessary?
EDIT: btw, when I run the method seen above, I do not see any output even though the file is being executed.