You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Kevin Telford (JIRA)" <ji...@apache.org> on 2010/10/13 02:40:32 UTC

[jira] Created: (EXEC-49) "Write dead end" IOException when using Piped streams w/PumpStreamHandler

"Write dead end" IOException when using Piped streams w/PumpStreamHandler
-------------------------------------------------------------------------

                 Key: EXEC-49
                 URL: https://issues.apache.org/jira/browse/EXEC-49
             Project: Commons Exec
          Issue Type: Bug
    Affects Versions: 1.1
         Environment: RHEL 5, Ubuntu 10.04
            Reporter: Kevin Telford
            Priority: Minor


{code:title=Sad Trombone}
java.io.IOException: Write end dead
	at java.io.PipedInputStream.read(PipedInputStream.java:294)
	at com.mycompany.commonsexecrunner.App.main(App.java:48)
{code}

I came across this issue when I was trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream.  The following code will produce the error.  The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break.

{code:title=Throws IOException}
    public static void main(String[] args) {

        System.out.println("Hello world");

        CommandLine cl = CommandLine.parse("/bin/ls");
        cl.addArgument("/opt");

        DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
        PipedOutputStream stdout = new PipedOutputStream();
        PumpStreamHandler psh = new PumpStreamHandler(stdout);
        Executor exec = new DefaultExecutor();
        exec.setStreamHandler(psh);

        try {
            System.out.println("Preparing to execute process - commandLine=" + cl.toString());
            exec.execute(cl, handler);
            System.out.println("Process spun off successfully - process=" + cl.getExecutable());
        } catch (ExecuteException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        
        PipedInputStream pis = null;
        try {
            pis = new PipedInputStream(stdout);
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        int x;
        try {
            while ((x = pis.read()) >= 0) {
                System.out.println("pis.available() " + pis.available());
                System.out.println("x " + x);
            }
        } catch  (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                pis.close();
            } catch (IOException ex) {
            }
        }

        System.out.println("Goodbye world");

    }
{code}

I was able to mitigate the error by modifying the createProcessOutputPump() method in the PumpStreamHandler class to accept the boolean value closeWhenExhausted, like was used for the setProcessInputStream() method.
{code}
protected void createProcessOutputPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
    outputThread = createPump(is, os, closeWhenExhausted);
}
{code}

This solution isn't implemented in the best way because in the end you have to pass a boolean value all the way down and it's kind of messy, but its a start.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (EXEC-49) "Write dead end" IOException when using Piped streams w/PumpStreamHandler

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/EXEC-49?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Siegfried Goeschl updated EXEC-49:
----------------------------------

    Fix Version/s:     (was: 1.1.1)
                   1.2

> "Write dead end" IOException when using Piped streams w/PumpStreamHandler
> -------------------------------------------------------------------------
>
>                 Key: EXEC-49
>                 URL: https://issues.apache.org/jira/browse/EXEC-49
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RHEL 5, Ubuntu 10.04
>            Reporter: Kevin Telford
>            Assignee: Siegfried Goeschl
>            Priority: Minor
>             Fix For: 1.2
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> {code:title=Sad Trombone}
> java.io.IOException: Write end dead
> 	at java.io.PipedInputStream.read(PipedInputStream.java:294)
> 	at com.mycompany.commonsexecrunner.App.main(App.java:48)
> {code}
> I came across this issue when I was trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream.  The following code will produce the error.  The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break.
> {code:title=Throws IOException}
>     public static void main(String[] args) {
>         System.out.println("Hello world");
>         CommandLine cl = CommandLine.parse("/bin/ls");
>         cl.addArgument("/opt");
>         DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
>         PipedOutputStream stdout = new PipedOutputStream();
>         PumpStreamHandler psh = new PumpStreamHandler(stdout);
>         Executor exec = new DefaultExecutor();
>         exec.setStreamHandler(psh);
>         try {
>             System.out.println("Preparing to execute process - commandLine=" + cl.toString());
>             exec.execute(cl, handler);
>             System.out.println("Process spun off successfully - process=" + cl.getExecutable());
>         } catch (ExecuteException ex) {
>             ex.printStackTrace();
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         
>         PipedInputStream pis = null;
>         try {
>             pis = new PipedInputStream(stdout);
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         int x;
>         try {
>             while ((x = pis.read()) >= 0) {
>                 System.out.println("pis.available() " + pis.available());
>                 System.out.println("x " + x);
>             }
>         } catch  (IOException ex) {
>             ex.printStackTrace();
>         } finally {
>             try {
>                 pis.close();
>             } catch (IOException ex) {
>             }
>         }
>         System.out.println("Goodbye world");
>     }
> {code}
> I was able to mitigate the error by modifying the createProcessOutputPump() method in the PumpStreamHandler class to accept the boolean value closeWhenExhausted, like was used for the setProcessInputStream() method.
> {code}
> protected void createProcessOutputPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
>     outputThread = createPump(is, os, closeWhenExhausted);
> }
> {code}
> This solution isn't implemented in the best way because in the end you have to pass a boolean value all the way down and it's kind of messy, but its a start.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-49) "Write dead end" IOException when using Piped streams w/PumpStreamHandler

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-49?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924384#action_12924384 ] 

Siegfried Goeschl commented on EXEC-49:
---------------------------------------

Hi Kevin - problem confirmed and really glad that you took the time to add the test case ... :-) 

> "Write dead end" IOException when using Piped streams w/PumpStreamHandler
> -------------------------------------------------------------------------
>
>                 Key: EXEC-49
>                 URL: https://issues.apache.org/jira/browse/EXEC-49
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RHEL 5, Ubuntu 10.04
>            Reporter: Kevin Telford
>            Assignee: Siegfried Goeschl
>            Priority: Minor
>             Fix For: 1.1.1
>
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> {code:title=Sad Trombone}
> java.io.IOException: Write end dead
> 	at java.io.PipedInputStream.read(PipedInputStream.java:294)
> 	at com.mycompany.commonsexecrunner.App.main(App.java:48)
> {code}
> I came across this issue when I was trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream.  The following code will produce the error.  The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break.
> {code:title=Throws IOException}
>     public static void main(String[] args) {
>         System.out.println("Hello world");
>         CommandLine cl = CommandLine.parse("/bin/ls");
>         cl.addArgument("/opt");
>         DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
>         PipedOutputStream stdout = new PipedOutputStream();
>         PumpStreamHandler psh = new PumpStreamHandler(stdout);
>         Executor exec = new DefaultExecutor();
>         exec.setStreamHandler(psh);
>         try {
>             System.out.println("Preparing to execute process - commandLine=" + cl.toString());
>             exec.execute(cl, handler);
>             System.out.println("Process spun off successfully - process=" + cl.getExecutable());
>         } catch (ExecuteException ex) {
>             ex.printStackTrace();
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         
>         PipedInputStream pis = null;
>         try {
>             pis = new PipedInputStream(stdout);
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         int x;
>         try {
>             while ((x = pis.read()) >= 0) {
>                 System.out.println("pis.available() " + pis.available());
>                 System.out.println("x " + x);
>             }
>         } catch  (IOException ex) {
>             ex.printStackTrace();
>         } finally {
>             try {
>                 pis.close();
>             } catch (IOException ex) {
>             }
>         }
>         System.out.println("Goodbye world");
>     }
> {code}
> I was able to mitigate the error by modifying the createProcessOutputPump() method in the PumpStreamHandler class to accept the boolean value closeWhenExhausted, like was used for the setProcessInputStream() method.
> {code}
> protected void createProcessOutputPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
>     outputThread = createPump(is, os, closeWhenExhausted);
> }
> {code}
> This solution isn't implemented in the best way because in the end you have to pass a boolean value all the way down and it's kind of messy, but its a start.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (EXEC-49) "Write dead end" IOException when using Piped streams w/PumpStreamHandler

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/EXEC-49?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Siegfried Goeschl updated EXEC-49:
----------------------------------

         Fix Version/s: 1.1.1
    Remaining Estimate: 4h  (was: 24h)
     Original Estimate: 4h  (was: 24h)

> "Write dead end" IOException when using Piped streams w/PumpStreamHandler
> -------------------------------------------------------------------------
>
>                 Key: EXEC-49
>                 URL: https://issues.apache.org/jira/browse/EXEC-49
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RHEL 5, Ubuntu 10.04
>            Reporter: Kevin Telford
>            Assignee: Siegfried Goeschl
>            Priority: Minor
>             Fix For: 1.1.1
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> {code:title=Sad Trombone}
> java.io.IOException: Write end dead
> 	at java.io.PipedInputStream.read(PipedInputStream.java:294)
> 	at com.mycompany.commonsexecrunner.App.main(App.java:48)
> {code}
> I came across this issue when I was trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream.  The following code will produce the error.  The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break.
> {code:title=Throws IOException}
>     public static void main(String[] args) {
>         System.out.println("Hello world");
>         CommandLine cl = CommandLine.parse("/bin/ls");
>         cl.addArgument("/opt");
>         DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
>         PipedOutputStream stdout = new PipedOutputStream();
>         PumpStreamHandler psh = new PumpStreamHandler(stdout);
>         Executor exec = new DefaultExecutor();
>         exec.setStreamHandler(psh);
>         try {
>             System.out.println("Preparing to execute process - commandLine=" + cl.toString());
>             exec.execute(cl, handler);
>             System.out.println("Process spun off successfully - process=" + cl.getExecutable());
>         } catch (ExecuteException ex) {
>             ex.printStackTrace();
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         
>         PipedInputStream pis = null;
>         try {
>             pis = new PipedInputStream(stdout);
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         int x;
>         try {
>             while ((x = pis.read()) >= 0) {
>                 System.out.println("pis.available() " + pis.available());
>                 System.out.println("x " + x);
>             }
>         } catch  (IOException ex) {
>             ex.printStackTrace();
>         } finally {
>             try {
>                 pis.close();
>             } catch (IOException ex) {
>             }
>         }
>         System.out.println("Goodbye world");
>     }
> {code}
> I was able to mitigate the error by modifying the createProcessOutputPump() method in the PumpStreamHandler class to accept the boolean value closeWhenExhausted, like was used for the setProcessInputStream() method.
> {code}
> protected void createProcessOutputPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
>     outputThread = createPump(is, os, closeWhenExhausted);
> }
> {code}
> This solution isn't implemented in the best way because in the end you have to pass a boolean value all the way down and it's kind of messy, but its a start.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (EXEC-49) "Write dead end" IOException when using Piped streams w/PumpStreamHandler

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/EXEC-49?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Siegfried Goeschl updated EXEC-49:
----------------------------------

    Attachment: exec-49.patch

Patch for fixing exec-49

> "Write dead end" IOException when using Piped streams w/PumpStreamHandler
> -------------------------------------------------------------------------
>
>                 Key: EXEC-49
>                 URL: https://issues.apache.org/jira/browse/EXEC-49
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RHEL 5, Ubuntu 10.04
>            Reporter: Kevin Telford
>            Assignee: Siegfried Goeschl
>            Priority: Minor
>             Fix For: 1.2
>
>         Attachments: exec-49.patch
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> {code:title=Sad Trombone}
> java.io.IOException: Write end dead
> 	at java.io.PipedInputStream.read(PipedInputStream.java:294)
> 	at com.mycompany.commonsexecrunner.App.main(App.java:48)
> {code}
> I came across this issue when I was trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream.  The following code will produce the error.  The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break.
> {code:title=Throws IOException}
>     public static void main(String[] args) {
>         System.out.println("Hello world");
>         CommandLine cl = CommandLine.parse("/bin/ls");
>         cl.addArgument("/opt");
>         DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
>         PipedOutputStream stdout = new PipedOutputStream();
>         PumpStreamHandler psh = new PumpStreamHandler(stdout);
>         Executor exec = new DefaultExecutor();
>         exec.setStreamHandler(psh);
>         try {
>             System.out.println("Preparing to execute process - commandLine=" + cl.toString());
>             exec.execute(cl, handler);
>             System.out.println("Process spun off successfully - process=" + cl.getExecutable());
>         } catch (ExecuteException ex) {
>             ex.printStackTrace();
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         
>         PipedInputStream pis = null;
>         try {
>             pis = new PipedInputStream(stdout);
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         int x;
>         try {
>             while ((x = pis.read()) >= 0) {
>                 System.out.println("pis.available() " + pis.available());
>                 System.out.println("x " + x);
>             }
>         } catch  (IOException ex) {
>             ex.printStackTrace();
>         } finally {
>             try {
>                 pis.close();
>             } catch (IOException ex) {
>             }
>         }
>         System.out.println("Goodbye world");
>     }
> {code}
> I was able to mitigate the error by modifying the createProcessOutputPump() method in the PumpStreamHandler class to accept the boolean value closeWhenExhausted, like was used for the setProcessInputStream() method.
> {code}
> protected void createProcessOutputPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
>     outputThread = createPump(is, os, closeWhenExhausted);
> }
> {code}
> This solution isn't implemented in the best way because in the end you have to pass a boolean value all the way down and it's kind of messy, but its a start.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (EXEC-49) "Write dead end" IOException when using Piped streams w/PumpStreamHandler

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/EXEC-49?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Siegfried Goeschl resolved EXEC-49.
-----------------------------------

    Resolution: Fixed

> "Write dead end" IOException when using Piped streams w/PumpStreamHandler
> -------------------------------------------------------------------------
>
>                 Key: EXEC-49
>                 URL: https://issues.apache.org/jira/browse/EXEC-49
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.1
>         Environment: RHEL 5, Ubuntu 10.04
>            Reporter: Kevin Telford
>            Assignee: Siegfried Goeschl
>            Priority: Minor
>             Fix For: 1.2
>
>         Attachments: exec-49.patch
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> {code:title=Sad Trombone}
> java.io.IOException: Write end dead
> 	at java.io.PipedInputStream.read(PipedInputStream.java:294)
> 	at com.mycompany.commonsexecrunner.App.main(App.java:48)
> {code}
> I came across this issue when I was trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream.  The following code will produce the error.  The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break.
> {code:title=Throws IOException}
>     public static void main(String[] args) {
>         System.out.println("Hello world");
>         CommandLine cl = CommandLine.parse("/bin/ls");
>         cl.addArgument("/opt");
>         DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
>         PipedOutputStream stdout = new PipedOutputStream();
>         PumpStreamHandler psh = new PumpStreamHandler(stdout);
>         Executor exec = new DefaultExecutor();
>         exec.setStreamHandler(psh);
>         try {
>             System.out.println("Preparing to execute process - commandLine=" + cl.toString());
>             exec.execute(cl, handler);
>             System.out.println("Process spun off successfully - process=" + cl.getExecutable());
>         } catch (ExecuteException ex) {
>             ex.printStackTrace();
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         
>         PipedInputStream pis = null;
>         try {
>             pis = new PipedInputStream(stdout);
>         } catch (IOException ex) {
>             ex.printStackTrace();
>         }
>         int x;
>         try {
>             while ((x = pis.read()) >= 0) {
>                 System.out.println("pis.available() " + pis.available());
>                 System.out.println("x " + x);
>             }
>         } catch  (IOException ex) {
>             ex.printStackTrace();
>         } finally {
>             try {
>                 pis.close();
>             } catch (IOException ex) {
>             }
>         }
>         System.out.println("Goodbye world");
>     }
> {code}
> I was able to mitigate the error by modifying the createProcessOutputPump() method in the PumpStreamHandler class to accept the boolean value closeWhenExhausted, like was used for the setProcessInputStream() method.
> {code}
> protected void createProcessOutputPump(final InputStream is, final OutputStream os, final boolean closeWhenExhausted) {
>     outputThread = createPump(is, os, closeWhenExhausted);
> }
> {code}
> This solution isn't implemented in the best way because in the end you have to pass a boolean value all the way down and it's kind of messy, but its a start.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.