From: Chad Fowler Date: 2004-02-26T20:49:24+09:00 Subject: Re: Nested popens under OSX On Feb 19, 2004, at 12:39 PM, Dave Thomas wrote: > The following code fails under OSX: > > - - - - - - - - - - > code = %q{ > pipe = IO.popen("-","w+") > if pipe > pipe.puts "Get a job!" > $stderr.puts "Child says '#{pipe.gets.chomp}'" > else > $stderr.puts "Dad says '#{gets.chomp}'" > puts "OK" > end > } > > require 'rbconfig' > > ruby = open("|ruby 2>&1", "w+") > ruby.puts code > ruby.close_write > result = ruby.readlines > ruby.close > > puts result > - - - - - - - - - - > > I get: > > dave[Work/rubybook 11:33:33] ruby t.rb > -:7: private method `chomp' called for nil:NilClass (NoMethodError) > -:5: private method `chomp' called for nil:NilClass (NoMethodError) > dave[Work/rubybook 11:34:06] ruby t.rb > -:7: private method `chomp' called for nil:NilClass (NoMethodError) > -:4:in `write': Broken pipe (Errno::EPIPE) > from -:4:in `puts' > from -:4 > > However it works fine under Linux. > > If I run just the code in 'code' it works fine. > > Am I doing something stupid (the likely case), or is there a problem > running popen inside a process that's run using popen? > > I wasn't able to find the problem, but I can confirm that I see the same results on Mac OS with ruby 1.8.1 (2003-12-25) [powerpc-darwin]. To simplify things, I took the "code" part and put it in a separate file (brokenpipes) and then did: tashi-delek:~/download/ruby-1.8.1 chadfowler$ cat brokenpipes |ruby 2>&1 Dad is 992 -:9: private method `chomp' called for nil:NilClass (NoMethodError) -:3:in `write': Broken pipe (Errno::EPIPE) from -:3:in `puts' from -:3 I spent a little bit of fruitless time in the debugger and then realized better go avoid being late for work! Chad