class Mixlib::ShellOut

def initialize(*command_args)

cmd.run_command # etc.
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:
variables etc) as done by the OS in an actual login
* +login+: Whether to simulate a login (set secondary groups, primary group, environment
long-running commands.
the parent's stdout so that users may observe the progress of
child process. Generally this is used to copy data from the child to
operator +<<+) that will receive data as ShellOut reads it from the
* +live_stream+: An IO or Logger-like object (must respond to the append
default).
is a safe value, though on newer Linux systems the capacity is 64k by
data should not exceed the system's default pipe capacity (4096 bytes
launched. The child's stdin stream will be a pipe, so the size of input
written to the child process' stdin stream before the process is
* +input+: A String of data to be passed to the subcommand. This is
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
is run.
* +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, @process_status = '', '', ''
  @live_stdout = @live_stderr = nil
  @input = nil
  @log_level = :debug
  @log_tag = nil
  @environment = {}
  @cwd = nil
  @valid_exit_codes = [0]
  @terminate_reason = nil
  @timeout = nil
  if command_args.last.is_a?(Hash)
    parse_options(command_args.pop)
  end
  @command = command_args.size == 1 ? command_args.first : command_args
end