class EventMachine::WinRM::Shell
Attributes
client[RW]
remote_id[RW]
server[RW]
Public Class Methods
new(client, server)
click to toggle source
# File lib/em-winrm/shell.rb, line 26 def initialize(client, server) @client = client @server = server @remote_id = client.open_shell WinRM::Log.debug("#{server.host}[#{@remote_id}] => :shell_open") @out_channel = EM::Channel.new @err_channel = EM::Channel.new end
Public Instance Methods
close()
click to toggle source
Close and cleanup a shell
# File lib/em-winrm/shell.rb, line 76 def close r = client.close_shell(@remote_id) WinRM::Log.debug("#{server.host}[#{@remote_id}] => :shell_close") @on_close.call(r,@last_exit_code) if @on_close end
on_close(&block)
click to toggle source
called whenever the shell is closed
# File lib/em-winrm/shell.rb, line 52 def on_close(&block) @on_close = block end
on_error(&block)
click to toggle source
called whenever the shell has error output
# File lib/em-winrm/shell.rb, line 45 def on_error(&block) @err_channel.subscribe block end
on_output(&block)
click to toggle source
called whenever the shell has output
# File lib/em-winrm/shell.rb, line 38 def on_output(&block) @out_channel.subscribe block end
run_command(command)
click to toggle source
Open a shell and run a comamnd
# File lib/em-winrm/shell.rb, line 59 def run_command(command) command_id = client.run_command(@remote_id, command) WinRM::Log.debug("#{server.host}[#{@remote_id}] => :run_command[#{command}]") output=client.get_command_output(@remote_id, command_id) do |out,error| @out_channel.push(out) if out @err_channel.push(error) if error end client.cleanup_command(@remote_id, command_id) WinRM::Log.debug("#{server.host}[#{@remote_id}] => :command_cleanup[#{command}]") @last_exit_code = output[:exitcode] close output[:exitcode] end