gpt4 book ai didi

ruby - 如何将数据通过管道传输到通过标准输入上的 Net::SSH 启动的进程?

转载 作者:数据小太阳 更新时间:2023-10-29 06:46:46 27 4
gpt4 key购买 nike

我正在本地机器上生成数据源,我想通过 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com