InputStream.read does not return

H

Henning Moll

Hi!

I have a big problem with the following code:

---code---
import java.io.*;

public class DDD {
public static void main(String[] args) throws IOException
{
String command = "/path_to/bbb";

/* bbb is a shell script containing the following lines:
* ---snip---
* #!/bin/sh
* sleep 333
* echo done
* ---snip---
*/

Process pr = Runtime.getRuntime().exec(command);

int b;
while((b = pr.getInputStream().read()) != -1)
{
System.out.print((char)b);
}
}
}
---code---

No problem if we just wait the 333 seconds. The program prints 'done' an exits. But:
If you kill the script while the sleep is running, read() doesn't return ever.
(Note: kill the script, not the sleep process!).

What am i doing wrong? How to handle this?

Henning
 
H

Henning Moll

If you kill the script while the sleep is running, read() doesn't return ever.
(Note: kill the script, not the sleep process!).

What am i doing wrong? How to handle this?

Though the process chain is started through the shell script, the
InputStream is assigned to the sleep sub-process (at least while sleep
is running and output is/may comming from there....)

Killing the script does not kill the subprocess and that's the reason
why the InputStream does not give an EOF (until sleep finishes...)
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top