How to fix hanging popen3 in Ruby?
質問
I am getting unexpected behaviour using popen3, which I want to use to run a command like tool ala cmd < file1 > file2
. The below example hangs, so that stdout done
is never reached. Using other tools than cat
may cause hanging, so that stdin done
is never reached. I suspect, I am suffering from buffering, but how do I fix this?
#!/usr/bin/env ruby
require 'open3'
Open3.popen3("cat") do |stdin, stdout, stderr, wait_thr|
stdin.puts "foobar"
puts "stdin done"
stdout.each_line { |line| puts line }
puts "stdout done"
puts wait_thr.value
end
puts "all done"
正しい解決策はありません
所属していません StackOverflow