Skip to content

Instantly share code, notes, and snippets.

@andydna
Last active February 15, 2018 02:41
Show Gist options
  • Save andydna/644c2b63ec9c8ccbd533b6c31a340c55 to your computer and use it in GitHub Desktop.
Save andydna/644c2b63ec9c8ccbd533b6c31a340c55 to your computer and use it in GitHub Desktop.
# test/echo_loop.rb
loop do
puts $stdin.gets
end
# elsewhere
require 'open3'
# this works
stdin, stdout, stderr, wait_thr = Open3.popen3("dc")
loop do
stdin.puts "2 1 + p"
res = stdout.gets
puts res
sleep 1
end
# this doesn't
stdin, stdout, stderr, waiter = Open3.popen3('ruby test/echo_loop.rb')
stdin.puts 'hello'
res = stdout.gets # hangs here. what am i missing/doing wrong?
# i want to stdin.puts "something"
# and stdout.gets "something"
# for testing shelling out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment