class Toys::Utils::Exec::Result

The result returned from a subcommand execution. This includes the identifying name of the execution (if any), the result status of the execution, and any captured stream output.

Possible result statuses are:

*  The process failed to start. {Result#failed?} will return true, and
   {Result#exception} will return an exception describing the failure
   (often an errno).
*  The process executed and exited with a normal exit code. Either
   {Result#success?} or {Result#error?} will return true, and
   {Result.exit_code} will return the numeric exit code.
*  The process executed but was terminated by an uncaught signal.
   {Result#signaled?} will return true, and {Result#signal_code} will
   return the numeric signal code.

Attributes

captured_err[R]

The captured error string.

@return [String] The string captured from stderr. @return [nil] if the command was not configured to capture stderr.

captured_out[R]

The captured output string.

@return [String] The string captured from stdout. @return [nil] if the command was not configured to capture stdout.

exception[R]

The exception raised if a process couldn't be started.

Exactly one of {#exception} and {#status} will be non-nil. Exactly one of {#exception}, {#exit_code}, or {#signal_code} will be non-nil.

@return [Exception] The exception raised from process start. @return [nil] if the process started successfully.

name[R]

The subcommand's name.

@return [Object]

status[R]

The Ruby process status object, providing various information about the ending state of the process.

Exactly one of {#exception} and {#status} will be non-nil.

@return [Process::Status] The status, if the process was successfully

spanwed and terminated.

@return [nil] if the process could not be started.

Public Class Methods

new(name, out, err, status, exception) click to toggle source

@private

# File lib/toys/utils/exec.rb, line 803
def initialize(name, out, err, status, exception)
  @name = name
  @captured_out = out
  @captured_err = err
  @status = status
  @exception = exception
end

Public Instance Methods

error?() click to toggle source

Returns true if the subprocess terminated with a nonzero status, or false if the process failed to start, terminated due to a signal, or returned a zero status.

@return [Boolean]

# File lib/toys/utils/exec.rb, line 927
def error?
  code = exit_code
  !code.nil? && !code.zero?
end
exit_code() click to toggle source

The numeric status code for a process that exited normally,

Exactly one of {#exception}, {#exit_code}, or {#signal_code} will be non-nil.

@return [Integer] the numeric status code, if the process started

successfully and exited normally.

@return [nil] if the process did not start successfully, or was

terminated by an uncaught signal.
# File lib/toys/utils/exec.rb, line 869
def exit_code
  status&.exitstatus
end
failed?() click to toggle source

Returns true if the subprocess failed to start, or false if the process was able to execute.

@return [Boolean]

# File lib/toys/utils/exec.rb, line 894
def failed?
  status.nil?
end
signal_code() click to toggle source

The numeric signal code that caused process termination.

Exactly one of {#exception}, {#exit_code}, or {#signal_code} will be non-nil.

@return [Integer] The signal that caused the process to terminate. @return [nil] if the process did not start successfully, or executed

and exited with a normal exit code.
# File lib/toys/utils/exec.rb, line 883
def signal_code
  status&.termsig
end
Also aliased as: term_signal
signaled?() click to toggle source

Returns true if the subprocess terminated due to an unhandled signal, or false if the process failed to start or exited normally.

@return [Boolean]

# File lib/toys/utils/exec.rb, line 904
def signaled?
  !signal_code.nil?
end
success?() click to toggle source

Returns true if the subprocess terminated with a zero status, or false if the process failed to start, terminated due to a signal, or returned a nonzero status.

@return [Boolean]

# File lib/toys/utils/exec.rb, line 915
def success?
  code = exit_code
  !code.nil? && code.zero?
end
term_signal()
Alias for: signal_code