Module: ProcessHelper

Defined in:
lib/process_helper.rb,
lib/process_helper/version.rb,
lib/process_helper/empty_command_error.rb,
lib/process_helper/invalid_options_error.rb,
lib/process_helper/unprocessed_input_error.rb,
lib/process_helper/unexpected_exit_status_error.rb

Overview

Error which is raised when a command returns an unexpected exit status (return code)

Defined Under Namespace

Classes: EmptyCommandError, InvalidOptionsError, UnexpectedExitStatusError, UnprocessedInputError

Constant Summary collapse

VERSION =
'0.0.2'

Instance Method Summary collapse

Instance Method Details

#process(cmd, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/process_helper.rb', line 10

def process(cmd, options = {})
  cmd = cmd.to_s
  fail ProcessHelper::EmptyCommandError, 'command must not be empty' if cmd.empty?
  options = options.dup
  options_processing(options)
  Open3.popen2e(cmd) do |stdin, stdout_and_stderr, wait_thr|
    always_puts_output = (options[:puts_output] == :always)
    output = get_output(
      stdin,
      stdout_and_stderr,
      options[:input_lines],
      always_puts_output,
      options[:timeout]
    )
    stdin.close
    handle_exit_status(cmd, options, output, wait_thr)
    output
  end
end