Process causes its input stream to block (?)

  • Thread starter Robert J. Hansen
  • Start date
R

Robert J. Hansen

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);
}

===
 
G

Gordon Beaton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top