Ben Browning created JRUBY-6291:
-----------------------------------

             Summary: Closing One Stream From IO.popen4 Results in Stream 
Closed Error When Reading Other Streams
                 Key: JRUBY-6291
                 URL: https://jira.codehaus.org/browse/JRUBY-6291
             Project: JRuby
          Issue Type: Bug
    Affects Versions: JRuby 1.7
         Environment: Java 6
            Reporter: Ben Browning
            Assignee: Thomas E Enebo


The small snippet below results in an {{IOError: Stream closed}} on the 
{{stdout_io.each_line}} line. Removing the {{stdin.close}} gets rid of the 
error.

{code}
IO.popen4("ls") do |pid, stdin, stdout, stderr|
  stdin.close
  [
   Thread.new(stdout) {|stdout_io|
     stdout_io.each_line do |l|
       STDOUT.puts l
       STDOUT.flush
     end
     stdout_io.close
   },

   Thread.new(stderr) {|stderr_io|
     stderr_io.each_line do |l|
       STDERR.puts l
       STDERR.flush
     end
   }
  ].each( &:join )
end
{code}


RubyIO's close2 method has code to destroy any spawned processes associated 
with an IO object that gets closed. So, the workaround is to not close any of 
the IO streams until the process has finished or the program has finished 
consuming the process output. See:

https://github.com/jruby/jruby/blob/master/src/org/jruby/RubyIO.java#L3810
https://github.com/jruby/jruby/blob/master/src/org/jruby/RubyIO.java#L2002

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to