我正在本地计算机上生成数据馈送,我希望通过Net :: SSH管道进入远程进程。
像
这样的东西echo foosball | sed 's/foo/bar/g'
只是echo foosball
部分将成为本地计算机上的数据源。
我不寻找的是:
data = "foosball"
ssh.exec!("echo #{data} | sed 's/foo/bar/g'")
我真的希望实时传输数据流;)
答案 0 :(得分:8)
好的,我明白了:
#!/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"