Class | Mixlib::ShellOut |
In: |
lib/mixlib/shellout/unix.rb
lib/mixlib/shellout/version.rb lib/mixlib/shellout/exceptions.rb lib/mixlib/shellout/windows.rb lib/mixlib/shellout.rb |
Parent: | Object |
VERSION | = | "1.1.0" |
READ_WAIT_TIME | = | 0.01 |
READ_SIZE | = | 4096 |
DEFAULT_READ_TIMEOUT | = | 600 |
DEFAULT_ENVIRONMENT | = | {'LC_ALL' => 'C'} |
command | [R] | The command to be executed. |
cwd | [RW] | Working directory for the subprocess. Normally set via options to new |
environment | [R] | Environment variables that will be set for the subcommand. Refer to the documentation of new to understand how ShellOut interprets this. |
execution_time | [R] | The amount of time the subcommand took to execute |
group | [RW] | Group the command will run as. Normally set via options passed to new |
input | [RW] | ShellOut will push data from :input down the stdin of the subprocss. Normally set via options passed to new. Default: nil |
live_stream | [RW] | When live_stream is set, stdout of the subprocess will be copied to it as the subprocess is running. For example, if live_stream is set to STDOUT, the command‘s output will be echoed to STDOUT. |
log_level | [RW] | The log level at which ShellOut should log. |
log_tag | [RW] | A string which will be prepended to the log message. |
logger | [RW] | If a logger is set, ShellOut will log a message before it executes the command. |
process_status_pipe | [R] | |
status | [R] | A Process::Status (or ducktype) object collected when the subprocess is reaped. |
stderr | [R] | Data written to stderr by the subprocess |
stderr_pipe | [R] | |
stdin_pipe | [R] | |
stdout | [R] | Data written to stdout by the subprocess |
stdout_pipe | [R] | |
timeout | [W] | The maximum time this command is allowed to run. Usually set via options to new |
umask | [R] | The umask that will be set for the subcommand. |
user | [RW] | User the command will run as. Normally set via options passed to new |
valid_exit_codes | [RW] | An Array of acceptable exit codes. error! uses this list to determine if the command was successful. Normally set via options to new |
Takes a single command, or a list of command fragments. These are used as arguments to Kernel.exec. See the Kernel.exec documentation for more explanation of how arguments are evaluated. The last argument can be an options Hash.
If the last argument is a Hash, it is removed from the list of args passed to exec and used as an options hash. The following options are available:
Invoke find(1) to search for .rb files:
find = Mixlib::ShellOut.new("find . -name '*.rb'") find.run_command # If all went well, the results are on +stdout+ puts find.stdout # find(1) prints diagnostic info to STDERR: puts "error messages" + find.stderr # Raise an exception if it didn't exit with 0 find.error!
Run a command as the www user with no extra ENV settings from +/tmp+
cmd = Mixlib::ShellOut.new("apachectl", "start", :user => 'www', :env => nil, :cwd => '/tmp') cmd.run_command # etc.
Checks the exitstatus against the set of valid_exit_codes. If exitstatus is not in the list of valid_exit_codes, calls +invalid!+, which raises an Exception.
nil:: | always returns nil when it does not raise |
::ShellCommandFailed:: | via +invalid!+ |
The exit status of the subprocess. Will be nil if the command is still running or died without setting an exit status (e.g., terminated by `kill -9`).
Creates a String showing the output of the command, including a banner showing the exact command executed. Used by +invalid!+ to show command results when the command exited with an unexpected status.
Raises a ShellCommandFailed exception, appending the command‘s stdout, stderr, and exitstatus to the exception message.
msg: A String to use as the basis of the exception message. The default explanation is very generic, providing a more informative message is highly encouraged.
ShellCommandFailed always
Run the command, writing the command‘s standard out and standard error to stdout and stderr, and saving its exit status object to status
returns self; stdout, stderr, status, and exitstatus will be populated with results of the command