我正在本地机器上生成数据源,我想通过 Net::SSH 将其传输到远程进程。
有点像
echo foosball | sed 's/foo/bar/g'
只是 echo foosball
部分将是本地计算机上的数据馈送。
我不要找的是:
data = "foosball"
ssh.exec!("echo #{data} | sed 's/foo/bar/g'")
我真的想要实时将数据流传输到流程中;)
最佳答案
好吧,我明白了:
#!/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"
关于ruby - 如何将数据通过管道传输到通过标准输入上的 Net::SSH 启动的进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3695138/