Skip to content

Instantly share code, notes, and snippets.

@KellyLSB
Last active December 15, 2015 01:29
Show Gist options
  • Save KellyLSB/5180520 to your computer and use it in GitHub Desktop.
Save KellyLSB/5180520 to your computer and use it in GitHub Desktop.
Getting input and output with popen3 in ruby simultaneously.
#!/usr/bin/env ruby
require 'open3'
Open3.popen3('ping 127.0.0.1') do |i,o,e,t|
Thread.new do
while true
begin
system("stty raw -echo")
str = STDIN.getc.chomp
ensure
system("stty -raw echo")
end
if str == "\u0003"
Process.kill(1, t.pid)
puts "Killing Process..."
break
else
puts "Got: #{str}"
end
end
end
until (line = o.gets).nil? do
puts "#{line.chomp}\r"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment