class Net::SSH::Connection::Session
def exec(command, status: nil, &block)
end
puts data
else
puts "ERROR: #{data}"
if stream == :stderr
ssh.exec "grep something /some/files" do |ch, stream, data|
callbacks. However, for most uses, this will be sufficient.
Net::SSH::Connection::Channel#exec, and then setting up the channel
This is effectively identical to calling #open_channel, and then
(see Session#loop) in order for the command to actually execute.
Note that this method returns immediately, and requires an event loop
(:stdout or :stderr), and the data (as a string).
arguments: the channel object, a symbol indicating the data type
the block is called for each data and extended data packet, with three
no block is given, all output is printed via $stdout and $stderr. Otherwise,
A convenience method for executing a command and interacting with it. If
def exec(command, status: nil, &block) open_channel do |channel| channel.exec(command) do |ch, success| raise "could not execute command: #{command.inspect}" unless success if status channel.on_request("exit-status") do |ch2, data| status[:exit_code] = data.read_long end channel.on_request("exit-signal") do |ch2, data| status[:exit_signal] = data.read_long end end channel.on_data do |ch2, data| if block block.call(ch2, :stdout, data) else $stdout.print(data) end end channel.on_extended_data do |ch2, type, data| if block block.call(ch2, :stderr, data) else $stderr.print(data) end end end end end