Class: Net::SSH::Connection::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/net-ssh-plus.rb

Instance Method Summary collapse

Instance Method Details

#detailed_exec!(command) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/net-ssh-plus.rb', line 25

def detailed_exec!(command)
  ret = {}

  channel = open_channel do |channel| 
    channel.exec(command) do |ch, success| 
      abort "FAILED: couldn't execute command (ssh.channel.exec failure)" unless success

      channel.on_data do |ch, data|  # stdout 
        ret[:stdout] ||= ""
        ret[:stdout] << data
      end 

      channel.on_extended_data do |ch, type, data| 
        next unless type == 1  # only handle stderr 
        ret[:stderr] ||= ""
        ret[:stderr] << data
      end 

      channel.on_request("exit-status") do |ch, data| 
        ret[:exit_code] = data.read_long 
      end 
      channel.on_request("exit-signal") do |ch, data| 
        ret[:exit_signal] = data.read_long
      end 
    end
  end # open_channel
  
  channel.wait

  return ret
end