I have a Process and a DataInputStream ("dis", in the code below)
hooked up to the Process's getInputStream(). When trying to read from
it, it reads just fine up to the very end. Once there's no more data
to be found, it blocks.
What's particularly vexing is that it's only one user who's having this
problem. For all other users, it's working just fine. The affected
system is XP SP2, if that matters.
I've tried using a BufferedReader and tried it as a plain-Jane
DataInputStream and as a ... etc. Nothing works. Does anyone here
have any ideas about what's happening, or how to get the code to
reliably detect eof?
(Incidentally, I apologize in advance if the following code is
misformatted. Google Groups tends to be code-unfriendly.)
===
StringBuffer output = new StringBuffer();
try {
byte[] buf = new byte[4096];
logNoNewline("Reading... got ");
int bytesRead = dis.read(buf);
while (bytesRead != -1) {
log(bytesRead + " bytes");
output.append(new String(buf, 0, bytesRead));
logNoNewline("Reading... got ");
bytesRead = dis.read(buf);
}
log("eof");
} catch (Exception e) {
log("FIXME: exception caught while dumping key information");
log("FIXME: " + e);
}
===
Gordon Beaton - 09 Apr 2006 09:16 GMT
> I have a Process and a DataInputStream ("dis", in the code below)
> hooked up to the Process's getInputStream(). When trying to read
> from it, it reads just fine up to the very end. Once there's no more
> data to be found, it blocks.
Note that "no more data" is not necessarily the same as "EOF". To
reach EOF, the writer end of the stream needs to be closed.
If you don't get EOF on the stream, you should be looking at what the
*writer* is doing, not the reader.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e