Wow never mind (Im sometimes dense) i think i figured it out I needed
to loop on output string inside the first loop.
-Mike
MMil...@gmail.com wrote:
> Im trying to automate some setupstuff
> However im having problems doing this on Windows It seems that the file
[quoted text clipped - 32 lines]
> System.out.println("exitVal: " + exitVal);
> }
Gordon Beaton - 17 Oct 2006 19:03 GMT
> Wow never mind (Im sometimes dense) i think i figured it out I
> needed to loop on output string inside the first loop.
What you actually need to do is read from both streams concurrently,
i.e. while the process is still running. You will eventually run into
problems if you attempt to read the streams sequentially as you've
shown here, since the process could block while writing to the stream
you haven't started reading yet.
If you use ProcessBuilder you can combine both streams and don't need
the extra Thread to read them.
/gordon

Signature
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
> Im trying to automate some setupstuff
> However im having problems doing this on Windows It seems that the file
[quoted text clipped - 32 lines]
> System.out.println("exitVal: " + exitVal);
> }
The problem you are running into is the normal catch22 situation with Process
and reading the stdout/stderr streams. You are reading the error stream until
it closes (i.e. the process completes), then you read the output stream. If the
output stream fills the buffer and blocks the process, the process won't exit
so the first while loop won't terminate. If you reverse the order in which you
read the streams it doesn't solve the problem, it only reverses the failure
mode.
What you need to do is read both streams in parallel, and this normally requires
at least 2 threads. Which thread reads which stream, and what the thread does
with the data, is totally dependent on the expected data and how it needs to be
processed.

Signature
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555