Java blocks after calling runtime.exec()
<p>First some code:</p>

<pre><code>    Runtime runtime = Runtime.getRuntime();
    String args[] = new String[2];
//  args[0] = "/bin/bash";
//  args[1] = "-c";
//  args[2] = "/usr/bin/rpm2cpio "+archiveFile.getCanonicalPath()+" | /bin/cpio -idmv";
    args[0] = "/usr/bin/rpm2cpio";
    args[1] = archiveFile.getCanonicalPath();
    Process rpm2cpioProcess = runtime.exec(args, null, dir);
//  System.out.println("started rpm2cpio");

    String args2[] = new String[3];
    args2[0] = "/bin/cpio";
    args2[1] = "-idmu";
    args2[2] = "--quiet";
    Process cpioProcess = runtime.exec(args2, null, dir);
//  System.out.println("started cpio");

    InputStream fromRpm2cpio = rpm2cpioProcess.getInputStream();
    new ProcessInputStreamer(rpm2cpioProcess.getErrorStream());
    OutputStream fromCpio = cpioProcess.getOutputStream();
    new PipedStreamer(fromRpm2cpio, fromCpio);
    new ProcessInputStreamer(cpioProcess.getErrorStream());
//  System.out.println("pipe created");
    while(cpioProcess!=null &amp;&amp; fromRpm2cpio!=null) {
        boolean doSleep = true;
//      System.out.println("waking up");
        if (cpioProcess!=null) {
            try {
                if (cpioProcess.exitValue()==0) {
                    cpioProcess = null;
                    doSleep = false;
                }
            } catch(IllegalThreadStateException e) {
            }
        }
        if (rpm2cpioProcess!=null) {
            try {
                if (rpm2cpioProcess.exitValue()==0) {
                    rpm2cpioProcess = null;
                    doSleep = false;
                }
            } catch(IllegalThreadStateException e) {
            }
        }
        if (doSleep) {
            Thread.sleep(30);
        }
//      System.out.println("still running");
    }
</code></pre>

<p>I'm trying to extract the content of an rpm archive. This code works fine after multiple modifications. My first attempt was to execute the next code through Java:</p>

<pre><code>/bin/bash -c '/usr/bin/rpm2cpio &lt;archive-file&gt; | /bin/cpio -idmv'
</code></pre>

<p>Which worked fine the first time I ran it (you can see it in the code commented above). The second time I ran the code it got blocked since the extracted files already existed. So I thought maybe it has to do with the piping and thus split the call into two separate processes. This didn't help much either. So I then modified the arguments of the /bin/cpio from '-idmv' to '-idmu --quiet' and now it works. Unfortunately the -u option overwrites existing files 'unconditionally' which is not really needed. My question is why does it block with -idmv and why doesn't it block with -idmu ?</p>
