I created a sub Process and I'm trying to read it output and print it. The process is a very simple python program that prints "Tick" every second and after some time exits.
The java code is:
[..]
try
{
ProcessBuilder pb = new ProcessBuilder(command);
pb.redirectErrorStream(true);
Process p = pb.start();
InputStreamReader in = new InputStreamReader(p.getInputStream());
BufferedReader br = new BufferedReader(in);
String line;
while ((line = br.readLine()) != null)
{
System.out.println(line);
System.out.flush();
}
}
catch (Exception ex)
{
System.out.println(ex.getMessage());
System.exit(1);
}
[..]
I only see the output on the console once the python program has exited. How can I read and print at the same time? Thanks