module Omnibus::Util

@author Seth Chisamore (<schisamo@opscode.com>)

Public Instance Methods

shellout(command, opts={}) click to toggle source

Shells out and runs command.

@param command [String] @param opts [Hash] the options passed to the initializer of the

+Mixlib::ShellOut+ instance.

@return [Mixlib::ShellOut] the underlying Mixlib::ShellOut instance

which which has +stdout+, +stderr+, +status+, and +exitstatus+
populated with results of the command.
# File lib/omnibus/util.rb, line 35
def shellout(command, opts={})
  STDOUT.sync = true
  default_options = {
    :live_stream => STDOUT,
    :timeout => 7200, # 2 hours
    :environment => {}
  }
  cmd = Mixlib::ShellOut.new(command, default_options.merge(opts))
  cmd.run_command
  cmd
end
shellout!(command, opts={}) click to toggle source

Similar to shellout method except it raises an exception if the command fails.

@see shellout

@raise [Mixlib::ShellOut::ShellCommandFailed] if exitstatus is not in

the list of +valid_exit_codes+.
# File lib/omnibus/util.rb, line 55
def shellout!(command, opts={})
  cmd = shellout(command, opts)
  cmd.error!
  cmd
end