Last active
February 17, 2017 17:50
-
-
Save pricees/db554baad344fc1d5b420c499a2b5166 to your computer and use it in GitHub Desktop.
interactive shell through ruby
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
require 'open3' | |
Open3.popen3("ssh -t myserver.net") do |stdin, stdout, stderr, th| | |
# STDIN | |
Thread.new { | |
until stdin.closed? do stdin.puts gets.strip; end | |
} | |
# STDOUT | |
thr_out = Thread.new { | |
while line = stdout.gets do puts line end | |
} | |
# STDERR | |
thr_err = Thread.new { | |
while line = stderr.gets do puts line end | |
} | |
Process::waitpid(th.pid) rescue nil # Thread may be dead | |
thr_out.join | |
thr_err.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment