I'm using ProcessBuilder
to execute a console application that takes one hour to execute.
I want to see output from the console in real time. In my code, the result only appears when the console application is finished.
Here is my code :
List<String> cmd;
ProcessBuilder pb = new ProcessBuilder();
pb.command(cmd);
Process process = pb.start();
process.getOutputStream().close();
InputStream processStdOutput = process.getInputStream();
Reader r = new InputStreamReader(processStdOutput);
BufferedReader br = new BufferedReader(r);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line); // the output is here
}
int w = process.waitFor();