Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Process causes its input stream to block (?)

Thread view: 
Robert J. Hansen - 09 Apr 2006 06:42 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.

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.