class Mixlib::ShellOut
def initialize(*command_args)
cmd = Mixlib::ShellOut.new("apachectl", "start", :user => 'www', :env => nil, :cwd => '/tmp')
Run a command as the +www+ user with no extra ENV settings from +/tmp+
find.error!
# Raise an exception if it didn't exit with 0
puts "error messages" + find.stderr
# find(1) prints diagnostic info to STDERR:
puts find.stdout
# If all went well, the results are on +stdout+
find.run_command
find = Mixlib::ShellOut.new("find . -name '*.rb'")
Invoke find(1) to search for .rb files:
=== Examples:
seconds. Note: the stdlib Timeout library is not used.
receiving any output (i.e., IO.select returned nil). Default is 60
total amount of time that ShellOut waited on the child process without
child process before raising an Exception. This is calculated as the
* +timeout+: a Numeric value for the number of seconds to wait on the
without changing the locale.
:environment => {'LC_ALL'=>nil, ...} to set other environment settings
use :environment => nil for *no* extra environment settings, or
to prevent issues with multibyte characters in Ruby 1.8. To avoid this,
is run. By default, the environment will *always* be set to 'LC_ALL' => 'C'
* +environment+: a Hash of environment variables to set before the command
+run_command+.
subprocess. This only has an effect if you call +error!+ after
* +returns+: one or more Integer values to use as valid exit codes for the
be treated as an octal integer
be sure to use two leading zeros so it's parsed as Octal. A string will
* +umask+: a umask to set before running the command. If given as an Integer,
* +cwd+: the directory to chdir to before running the command
* +group+: the group the command should run as. works similarly to +user+
with Etc.getpwnam
used as a uid. A string is treated as a username and resolved to a uid
* +user+: the user the commmand should run as. if an integer is given, it is
to exec and used as an options hash. The following options are available:
If the last argument is a Hash, it is removed from the list of args passed
=== Options:
options Hash.
explanation of how arguments are evaluated. The last argument can be an
as arguments to Kernel.exec. See the Kernel.exec documentation for more
Takes a single command, or a list of command fragments. These are used
=== Arguments:
def initialize(*command_args) @stdout, @stderr = '', '' @live_stream = nil @log_level = :debug @log_tag = nil @environment = DEFAULT_ENVIRONMENT @cwd = nil @valid_exit_codes = [0] if command_args.last.is_a?(Hash) parse_options(command_args.pop) end @command = command_args.size == 1 ? command_args.first : command_args end