Class: ProcessExecuter::Commands::Run Private

Inherits:
SpawnWithTimeout show all
Defined in:
lib/process_executer/commands/run.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Run a command and return the Result

Extends SpawnWithTimeout to provide the core functionality for ProcessExecuter.run.

It accepts all Process.spawn execution options plus the additional options timeout_after, raise_errors and logger.

This class wraps any stdout or stderr redirection destinations in a MonitoredPipe. This allows any class that implements #write to be used as an output redirection destination. This means that you can redirect to a StringIO which is not possible with Process.spawn.

Direct Known Subclasses

RunWithCapture

Instance Attribute Summary

Attributes inherited from SpawnWithTimeout

#command, #elapsed_time, #options, #pid, #result, #status, #timed_out

Instance Method Summary collapse

Methods inherited from SpawnWithTimeout

#initialize

Constructor Details

This class inherits a constructor from ProcessExecuter::Commands::SpawnWithTimeout

Instance Method Details

#callProcessExecuter::Result

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run a command and return the result

Wrap the stdout and stderr redirection destinations in pipes and then execute the command.

Examples:

options = ProcessExecuter::Options::RunOptions.new(raise_errors: true)
result = ProcessExecuter::Commands::Run.new('echo hello', options).call
result.success? # => true
result.exitstatus # => 0

Returns:

Raises:



51
52
53
54
55
56
57
58
59
60
# File 'lib/process_executer/commands/run.rb', line 51

def call
  opened_pipes = wrap_stdout_stderr
  super.tap do
    log_result
    raise_errors if options.raise_errors
  end
ensure
  opened_pipes.each_value(&:close)
  opened_pipes.each { |option_key, pipe| raise_pipe_error(option_key, pipe) }
end