Class: ProcessExecuter::Commands::RunWithCapture Private

Inherits:
Run show all
Defined in:
lib/process_executer/commands/run_with_capture.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.

Runs a subprocess, blocks until it completes, and returns the result

Extends Run to provide the core functionality for ProcessExecuter.run_with_capture.

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

Like Run, any stdout or stderr redirection destinations are wrapped in a MonitoredPipe.

Instance Attribute Summary collapse

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 Attribute Details

#stderr_bufferStringIO (readonly)

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.

The buffer used to capture stderr

Examples:

run.stderr_buffer #=> StringIO

Returns:

  • (StringIO)


78
79
80
# File 'lib/process_executer/commands/run_with_capture.rb', line 78

def stderr_buffer
  @stderr_buffer
end

#stdout_bufferStringIO (readonly)

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.

The buffer used to capture stdout

Examples:

run.stdout_buffer #=> StringIO

Returns:

  • (StringIO)


69
70
71
# File 'lib/process_executer/commands/run_with_capture.rb', line 69

def stdout_buffer
  @stdout_buffer
end

Instance Method Details

#callProcessExecuter::ResultWithCapture

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 which includes the captured output

Examples:

options = ProcessExecuter::Options::RunWithCaptureOptions.new(merge_output: false)
result = ProcessExecuter::Commands::RunWithCapture.new('echo hello', options).call
result.success? # => true
result.exitstatus # => 0
result.stdout # => "hello\n"

Returns:

Raises:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/process_executer/commands/run_with_capture.rb', line 47

def call
  @stdout_buffer = StringIO.new
  stdout_buffer.set_encoding(options.effective_stdout_encoding)
  @stderr_buffer = StringIO.new
  stderr_buffer.set_encoding(options.effective_stderr_encoding)

  update_capture_options

  begin
    super
  ensure
    log_command_output
  end
end