Module: ProcessHelper

Extended by:
ProcessHelper
Included in:
ProcessHelper
Defined in:
lib/process_helper.rb

Overview

Makes it easy to spawn Ruby sub-processes with guaranteed exit status handling, capturing and/or suppressing combined STDOUT and STDERR streams, providing STDIN input, timeouts, and running via a pseudo terminal.

Full documentation at github.com/thewoolleyman/process_helper

Defined Under Namespace

Classes: EmptyCommandError, InvalidOptionsError, TimeoutError, UnexpectedExitStatusError, UnprocessedInputError

Constant Summary collapse

VERSION =

Don’t forget to keep version in sync with gemspec

'0.1.1'.freeze

Instance Method Summary collapse

Instance Method Details

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/process_helper.rb', line 18

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)
  puts cmd if options[:log_cmd]
  output, process_status =
    if options[:pseudo_terminal]
      process_with_pseudo_terminal(cmd, options)
    else
      process_with_popen(cmd, options)
    end
  handle_exit_status(cmd, options, output, process_status)
  output
end