I think it may have something to do with each_line waiting for "\n". Does the same thing happen with just something like read?
On Wednesday, 23 January 2013 at 11:30 AM, Chris Berkhout wrote: > Hi ROROers, > > I'm trying to build something on top the ChildProcess gem that makes > it as easy in Ruby to pipe stuff between processes (and Ruby blocks), > as it is in the shell. > > It's basically working. To see it in action: > clone https://gist.github.com/4600139 pipes-gist && cd pipes-gist > gem install childprocess > ruby ./pipes.rb > > But, I wonder if someone can explain pipes to me a bit more... > > Calling IO.pipe creates a read and a write end: > r, w = IO.pipe > > I'm reading from the read end like this: > r.each_line { |line| puts "this came out of the pipe: #{line}" } > > When I'm done I close the write end: > w.close > > And I would expect that to send an EOF through the pipe, which > #each_line would see and cause it to stop (or yield the last partial > line). > > But it doesn't. #each_line never finishes. It keeps going until the > read end of the pipe is closed, and when that happens it raises an > IOError (... stream closed). > > Is there no more graceful way to close a pipe? > > Cheers, > Chris > > -- > You received this message because you are subscribed to the Google Groups > "Ruby or Rails Oceania" group. > To post to this group, send email to [email protected] > (mailto:[email protected]). > To unsubscribe from this group, send email to > [email protected] > (mailto:[email protected]). > For more options, visit this group at > http://groups.google.com/group/rails-oceania?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
