I am shelling to an external windows program which updates its progress by repeatedly pushing new lines to the error stream.
The command prompt looks something like this when it's running:
10% done
10% done
11% done
and so forth.
I'm having some success capturing this in my java application thusly:
Process process = Runtime.getRuntime().exec("my little command");
BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while((s = stdError.readLine())!=null)
{
System.out.println(s);
}
Unfortunately, as you may have guessed, there's a bit of a problem. The stdError.readLine()
blocks until there are +- 4000 bytes in the error stream, and only then prints each line out in quick session, before it hangs again.
I've tried changing the BufferedReader
buffer size, and using stdError.read(char [] cbuf, int off, int len)
with a small length, to no avail.
How do I fix this hanging issue?
Thanks in advance :)