Class: Cliqr::Executor::BufferedCommandRunner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cliqr/executor/command_runner_factory.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.

Used to buffer command output

Instance Method Summary collapse

Instance Method Details

#runHash

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 the command handler but redirect stdout to a buffer

Returns:

  • (Hash)

    The hash contains :stdout, :stderr and :status of the command



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cliqr/executor/command_runner_factory.rb', line 49

def run
  old_stdout = $stdout
  old_stderr = $stderr
  $stdout = old_stdout.is_a?(StringIO) ? old_stdout : StringIO.new('', 'w')
  $stderr = old_stderr.is_a?(StringIO) ? old_stderr : StringIO.new('', 'w')
  yield
  {
      :stdout => $stdout.string,
      :stderr => $stderr.string,
      :status => 0
  }
ensure
  $stdout = old_stdout
  $stderr = old_stderr
end