Last active
December 15, 2015 01:29
-
-
Save KellyLSB/5180520 to your computer and use it in GitHub Desktop.
Getting input and output with popen3 in ruby simultaneously.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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