Module: Tango::Shell

Included in:
Runner
Defined in:
lib/tango/shell.rb

Instance Method Summary collapse

Instance Method Details

#shell(command, *args) ⇒ Object



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

def shell(command, *args)
  options = { :echo => true, :env_vars => {} }
  options.merge!(args.pop) if args.last.is_a?(Hash)

  log "% #{command} #{args.join(' ')}\n\n" if options[:echo]

  pid, pipe = fork_and_exec(command, options[:env_vars], *args)
  output    = collect_output(pipe, options[:echo])
  Process.waitpid(pid)
  pipe.close

  log "" if options[:echo]

  OpenStruct.new(
    :output     => output,
    :status     => $?.exitstatus,
    :succeeded? => $?.success?,
    :failed?    => !$?.success?
  )
end

#shell!(command, *args) ⇒ Object



29
30
31
32
33
# File 'lib/tango/shell.rb', line 29

def shell!(command, *args)
  result = shell(command, *args)
  raise "Shell command failed with status #{result.status}" if result.failed?
  result
end