好吧,我想出来了:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
res = ""
c = Net::SSH.start("127.0.0.1", "xxx", :password => "xxx")
c.open_channel do |channel|
channel.exec("sed 's/foo/bar/g'") do |ch, success|
channel.on_data do |ch,data|
res << data
end
channel.send_data "foosball"
channel.eof!
end
end
c.loop
puts res # => "barsball"