The Source for Java Technology Collaboration
Webmaster Alert: Posting to Jive Forums is currently not working. Estimated time for fix is unknown.

Home » java.net Forums » JDK » Java SE

Thread: InputStream from Runtime.exec hangs under Linuxes

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Last Post: Jul 24, 2006 8:26 AM by: jchristi
kirillk

Posts: 15
InputStream from Runtime.exec hangs under Linuxes
Posted: Jul 24, 2006 5:59 AM
  Click to reply to this thread Reply

This is strange, I discovered that if I run a process and get an input stream Runtime.getRuntime().exec().getInputStream() - I can read only the very first line from it or sometimes just nothing.

It actually blocks at native method:
at java.io.FileInputStream.readBytes(Native Method)
at java.io.FileInputStream.read(FileInputStream.java:194)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
at java.io.BufferedInputStream.read(BufferedInputStream.java:313)

This is 100% reproducible under Linuxes, jdk1.4, runs with no problems on Windows and Macs.

Does anybody have a clue?

jchristi

Posts: 3
Re: InputStream from Runtime.exec hangs under Linuxes
Posted: Jul 24, 2006 8:26 AM   in response to: kirillk
  Click to reply to this thread Reply

Be sure to get both the input stream and the error stream, and consume/drain both of these.

I've seen that if you dont consume both, on some platforms, the child process will simply hang. If the stderr output of your child process varies in timing/content, this would explain your mention of "Sometimes" in your posting.

-JC




 XML java.net RSS