0

I have some code in which proc = Runtime.getRuntime().exec(cmd) is called to launch a subprocess, and then there is some communication between the parent and child processes. In some cases, I'm getting java.io.IOException: The pipe is being closed during calls to write() and flush() from the parent to the child. This happens sometimes but not every time.

My hypothesis here is that the subprocess is being launched (and therefore proc.getInput/OutputStream() works) but the parent process is trying to write to the child process before the child process is fully running/executing. Does this seem plausible? I don't have enough deep experience with the JVM to really feel confident. Currently my solution is to have the child process write to the parent, informing it that it's up and running; this works perfectly fine, but it would be nice to feel a bit more confident about it.

If any more code details or whatever are needed, I'd be happy to supply.

Thanks!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
mfsiega
  • 2,852
  • 19
  • 22
  • The child should block on reading if the parent hasn't written to the pipe yet. Is it possible the child is terminating immediately before the parent has a chance to write? – Jim Garrison Oct 22 '12 at 05:41
  • The parent is the one getting the exception, not the child. – mfsiega Oct 22 '12 at 13:41
  • I realize that. If the child were to end before the parent got a chance to write, you might get that error on the parent. – Jim Garrison Oct 22 '12 at 17:53

0 Answers0