如何使用popen3写入读写?

时间:2016-06-17 19:02:38

标签: ruby

我正在使用Windows而且我希望写一个程序,在我收到响应之后,就像这样:

Open3.popen3("ruby echo.rb") do |stdin, stdout, stderr, wait|
  stdin.puts("Hello\n")
  stdin.close
  got_this = stdout.read
  stdin.reopen # <- Not an existing function. What to do here?
  stdin.puts(got_this)
  puts stdout.read
  stdin.close
end

我的问题是,在关闭输出流之前似乎无法读取输入。我已经发现这篇文章,但似乎Windows上没有PTY支持: ruby popen3 -- how to repeatedly write to stdin & read stdout without re-opening process?

这是echo.rb的代码:

t = gets.chomp
puts "10"
t = gets.chomp
puts t+t

0 个答案:

没有答案