commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Price (JIRA)" <>
Subject [jira] [Created] (EXEC-102) "Stream closed" error in Java 8 when passing input to processes that don't consume it
Date Wed, 27 Jan 2016 22:14:39 GMT
Chris Price created EXEC-102:

             Summary: "Stream closed" error in Java 8 when passing input to processes that
don't consume it
                 Key: EXEC-102
             Project: Commons Exec
          Issue Type: Bug
            Reporter: Chris Price

When trying to pass an InputStream to a process (i.e. for it to be used as STDIN), I am getting
an IOException in Java 8 that I did not get in Java 7.

Here is a simple reproducer:

package foo;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.Executor;
import org.apache.commons.exec.PumpStreamHandler;


public class CommonsExecBinTrue {
    public static void main(String[] args) throws IOException {

        Executor exec = new DefaultExecutor();

        CommandLine cl = new CommandLine("/bin/true");

        String text = "hello";
        ByteArrayInputStream input =
                new ByteArrayInputStream(text.getBytes("UTF-8"));
        ByteArrayOutputStream output = new ByteArrayOutputStream();

        exec.setStreamHandler(new PumpStreamHandler(output, null, input));

        System.out.println("result: " + output.toString("UTF-8"));

This program would work fine in Java 7, but in Java 8 it fails with this stack trace:

Exception in thread "main" Stream closed
	at java.lang.ProcessBuilder$NullOutputStream.write(
	at org.apache.commons.exec.DefaultExecutor.closeProcessStreams(
	at org.apache.commons.exec.DefaultExecutor.executeInternal(
	at org.apache.commons.exec.DefaultExecutor.execute(
	at org.apache.commons.exec.DefaultExecutor.execute(
	at foo.CommonsExecBinTrue.main(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.intellij.rt.execution.application.AppMain.main(

This message was sent by Atlassian JIRA

View raw message