How can I output stdout right away? stdout will print after input is complete.
require 'open3' def run(cmd) Open3.popen3(cmd) do |stdin, stdout, stderr, thread| Thread.new do stdout.each {|l| puts l} end Thread.new do while thread.alive? stdin.puts $stdin.gets end end thread.join end end run ("ruby file_to_test.rb")
file_to_test.rb:
puts "please, enter s" puts "please, enter q" s = gets.chomp! q = gets.chomp! puts s puts q
The result after running main.rb:
somestring somestring2 please, enter s please, enter q somestring somestring2
How can I output stdout right away?
source share