Skip to content

Instantly share code, notes, and snippets.

@pricees
Last active February 17, 2017 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pricees/db554baad344fc1d5b420c499a2b5166 to your computer and use it in GitHub Desktop.
Save pricees/db554baad344fc1d5b420c499a2b5166 to your computer and use it in GitHub Desktop.
interactive shell through ruby
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