D
Dawa Ometto
Hi,
I would like to use the net/ssh gem to connect to an ssh server, execute
a command, and send data to the command's standard input. So far I've
managed to do this using the on_data callback:
ch.exec "mycommand" do |ch, success|
ch.on_data do |ch, data| #Wait for invitation on std-out and send
message on std-in
output << data
if input != nil then
ch.send_data(input.gsub("\n","\r")+"\n") #Fix to prevent
multi line data from ending the data stream, append newline
end
end
end
However, this is slightly suboptimal - it means that the listening
script has to send something to standard out before I can send data to
it's stdin. Does anyone have clue how this can be implemented without
using the on_data callback?
Kind regards,
Dawa
I would like to use the net/ssh gem to connect to an ssh server, execute
a command, and send data to the command's standard input. So far I've
managed to do this using the on_data callback:
ch.exec "mycommand" do |ch, success|
ch.on_data do |ch, data| #Wait for invitation on std-out and send
message on std-in
output << data
if input != nil then
ch.send_data(input.gsub("\n","\r")+"\n") #Fix to prevent
multi line data from ending the data stream, append newline
end
end
end
However, this is slightly suboptimal - it means that the listening
script has to send something to standard out before I can send data to
it's stdin. Does anyone have clue how this can be implemented without
using the on_data callback?
Kind regards,
Dawa