From: Alexy Khrabrov Date: 2007-11-10T07:34:31+09:00 Subject: Re: background process readling lines and responding Hey Szymon -- good to see you here! If, instead of "grep something", I give it a Ruby program which reads and writes lines, it works OK. I wonder what's different between these: -- a.rb: IO.popen("ruby b.rb", "r+") do |f| STDIN.each_line do |x| @write = f.puts x.to_s @read = f.gets puts "back: #{@read}" end end -- b.rb: STDOUT.sync = true def readWrite while @string = gets @string.chomp! puts "received => #{@string}" end end readWrite $ ruby a.rb /z/aha/ru/popen ruby a.rb abra back: received => abra cadabra back: received => cadabra ... -- can enter strings, they're echoed back. Now, let's call "grep abra" instead of b.rb: -- call-grep.rb: IO.popen("grep abra", "r+") do |f| STDIN.each_line do |x| puts "sending: #{x}" @write = f.puts x.to_s @read = f.gets puts "back: #{@read}" end end $ ruby call-grep.rb: /z/aha/ru/popen ruby call-grep.rb abra sending: abra cadabra -- already unresponsive. -- Posted via http://www.ruby-forum.com/.