Module: ImageOptim::Cmd
- Defined in:
- lib/image_optim/cmd.rb
Overview
Helper for running commands
Class Method Summary collapse
-
.capture(cmd) ⇒ Object
Run using backtick Return captured output Will raise SignalException if process was interrupted.
-
.run(*args) ⇒ Object
Run using ‘system` Return success status Will raise SignalException if process was interrupted.
Class Method Details
.capture(cmd) ⇒ Object
Run using backtick Return captured output Will raise SignalException if process was interrupted
42 43 44 45 46 47 48 |
# File 'lib/image_optim/cmd.rb', line 42 def capture(cmd) output = `#{cmd}` check_status! output end |
.run(*args) ⇒ Object
Run using ‘system` Return success status Will raise SignalException if process was interrupted
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/image_optim/cmd.rb', line 10 def run(*args) if Process.respond_to?(:spawn) if args.last.is_a?(Hash) args.last[Gem.win_platform? ? :new_pgroup : :pgroup] = true end begin pid = Process.spawn(*args) ensure yield pid if block_given? end begin Process.waitpid(pid) rescue Errno::ECHILD return end check_status! $CHILD_STATUS.success? else success = system(*args) check_status! success end end |