Class | Chef::ShellOut |
In: |
lib/chef/shell_out.rb
|
Parent: | Object |
Provides a simplified interface to shelling out yet still collecting both standard out and standard error and providing full control over environment, working directory, uid, gid, etc.
No means for passing input to the subprocess is provided, nor is there any way to inspect the output of the command as it is being read. If you need to do that, you have to use popen4 (in Chef::Mixin::Command)
Chef::ShellOut uses Kernel.fork() and is therefore unsuitable for Windows or jruby.
READ_WAIT_TIME | = | 0.01 |
READ_SIZE | = | 4096 |
DEFAULT_READ_TIMEOUT | = | 60 |
DEFAULT_ENVIRONMENT | = | {'LC_ALL' => 'C'} |
command | [R] | |
cwd | [RW] | |
environment | [R] | |
execution_time | [R] | |
group | [RW] | |
process_status_pipe | [R] | |
status | [R] | |
stderr | [R] | |
stderr_pipe | [R] | |
stdin_pipe | [R] | |
stdout | [R] | |
stdout_pipe | [R] | |
timeout | [W] | |
umask | [R] | |
user | [RW] | |
valid_exit_codes | [RW] |
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 = Chef::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 = Chef::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 |
Chef::Exceptions::ShellCommandFailed:: | via +invalid!+ |
Raises a Chef::Exceptions::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.
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