class WinRM::Shells::Cmd

Proxy to a remote cmd.exe shell

Public Class Methods

close_shell(connection_opts, transport, shell_id) click to toggle source
# File lib/winrm/shells/cmd.rb, line 27
def close_shell(connection_opts, transport, shell_id)
  msg = WinRM::WSMV::CloseShell.new(connection_opts, shell_id: shell_id)
  transport.send_request(msg.build)
end
finalize(connection_opts, transport, shell_id) click to toggle source
# File lib/winrm/shells/cmd.rb, line 23
def finalize(connection_opts, transport, shell_id)
  proc { Cmd.close_shell(connection_opts, transport, shell_id) }
end

Protected Instance Methods

open_shell() click to toggle source
# File lib/winrm/shells/cmd.rb, line 52
def open_shell
  msg = WinRM::WSMV::CreateShell.new(connection_opts, shell_opts)
  resp_doc = transport.send_request(msg.build)
  REXML::XPath.first(resp_doc, "//*[@Name='ShellId']").text
end
out_streams() click to toggle source
# File lib/winrm/shells/cmd.rb, line 58
def out_streams
  %w[stdout stderr]
end
response_reader() click to toggle source
# File lib/winrm/shells/cmd.rb, line 48
def response_reader
  @response_reader ||= WinRM::WSMV::ReceiveResponseReader.new(transport, logger)
end
send_command(command, arguments) click to toggle source
# File lib/winrm/shells/cmd.rb, line 35
def send_command(command, arguments)
  cmd_msg = WinRM::WSMV::Command.new(
    connection_opts,
    shell_id: shell_id,
    command: command,
    arguments: arguments
  )
  resp_doc = transport.send_request(cmd_msg.build)
  command_id = REXML::XPath.first(resp_doc, "//*[local-name() = 'CommandId']").text
  logger.debug("[WinRM] Command created for #{command} with id: #{command_id}")
  command_id
end