Skip to content

Instantly share code, notes, and snippets.

@djanowski
Created August 5, 2009 06:45
Show Gist options
  • Save djanowski/162546 to your computer and use it in GitHub Desktop.
Save djanowski/162546 to your computer and use it in GitHub Desktop.
require "open3"
commands = <<-EOS
echo 'foo'
cd /tmp
ls -1
EOS
threads = []
Open3.popen3("ssh -T localhost") do |stdin, stdout, stderr|
threads << Thread.new do
while line = stderr.gets
$stderr.puts(line)
end
end
threads << Thread.new do
while line = stdout.gets
$stdout.puts(line)
end
end
commands.each_line do |line|
stdin.puts(line)
end
stdin.close
threads.each {|t| t.join }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment