Class: RubySSH::ShellRunner
- Inherits:
-
Object
- Object
- RubySSH::ShellRunner
- Defined in:
- lib/ruby-ssh/shell_runner.rb
Instance Method Summary collapse
- #exec(script) ⇒ Object
-
#initialize(session) ⇒ ShellRunner
constructor
A new instance of ShellRunner.
Constructor Details
#initialize(session) ⇒ ShellRunner
Returns a new instance of ShellRunner.
3 4 5 |
# File 'lib/ruby-ssh/shell_runner.rb', line 3 def initialize(session) @session = session end |
Instance Method Details
#exec(script) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby-ssh/shell_runner.rb', line 7 def exec(script) stdout, stderr, exit_status = nil @session.open_channel do |channel| channel.on_data do |ch, data| stdout = data end channel.on_extended_data do |ch, type, data| stderr = data end channel.send_channel_request 'shell' do |ch, success| if success ch.send_data(script) ch.process ch.eof! else p "channel request error" end end channel.on_request "exit-status" do |ch, data| exit_status = data.read_long end end @session.loop RubySSH::Result.new(stdout: stdout, stderr: stderr, exit_status: exit_status) end |