class Remotus::Result

Class to standardize remote output from WinRM and SSH connections

Attributes

command[R]

@return [String] executed command

exit_code[R]

@return [Integer] exit code

output[R]

@return [String] all output (stdout and stderr interleaved)

stderr[R]

@return [String] standard error output

stdout[R]

@return [String] standard output

Public Class Methods

new(command, stdout, stderr, output, exit_code = nil) click to toggle source

Creates a new Result

@param [String] command command executed @param [String] stdout standard output @param [String] stderr standard error output @param [String] output all output (stdout and stderr interleaved) @param [Integer] exit_code exit code

# File lib/remotus/result.rb, line 32
def initialize(command, stdout, stderr, output, exit_code = nil)
  @command = command
  @stdout = stdout
  @stderr = stderr
  @output = output
  @exit_code = exit_code
end

Public Instance Methods

error!(accepted_exit_codes = [0]) click to toggle source

Raises an exception if an error was encountered

@param [Array] accepted_exit_codes integer array of acceptable exit codes

# File lib/remotus/result.rb, line 65
def error!(accepted_exit_codes = [0])
  return unless error?(accepted_exit_codes)

  raise Remotus::ResultError, "Error encountered executing #{@command}! Exit code #{@exit_code} was returned "\
    "while a value in #{accepted_exit_codes} was expected.\n#{output}"
end
error?(accepted_exit_codes = [0]) click to toggle source

Whether an error was encountered

@param [Array] accepted_exit_codes integer array of acceptable exit codes

@return [Boolean] Whether an error was encountered

# File lib/remotus/result.rb, line 56
def error?(accepted_exit_codes = [0])
  !Array(accepted_exit_codes).include?(@exit_code)
end
success?(accepted_exit_codes = [0]) click to toggle source

Whether the command was successful

@param [Array] accepted_exit_codes integer array of acceptable exit codes

@return [Boolean] Whether the command was successful

# File lib/remotus/result.rb, line 79
def success?(accepted_exit_codes = [0])
  !error?(accepted_exit_codes)
end
to_s() click to toggle source

Alias for all interleaved stdout and stderr output

@return [String] interleaved output

# File lib/remotus/result.rb, line 45
def to_s
  output
end