Skip to content

Instantly share code, notes, and snippets.

@sawanoboly
Last active August 29, 2015 13:57
Show Gist options
  • Save sawanoboly/9907848 to your computer and use it in GitHub Desktop.
Save sawanoboly/9907848 to your computer and use it in GitHub Desktop.
Chefの`shell_out`と`shell_out!`、違いと使い分け ref: http://qiita.com/sawanoboly/items/43bc9e15739355f9c533
> result = shell_out!('ps | grep hogehgoe', :returns => 1)
=> <Mixlib::ShellOut#18867260:
command: 'ps | grep hogehgoe'
process_status: #<Process::Status: pid 16586 exit 1>
stdout: ''
stderr: ''
child_pid: 16586
environment: {"LC_ALL"=>"C"}
timeout: 600
user:
group:
working_dir:
>
## ArrayでもOK
> result = shell_out!('ps | grep hogehgoe', :returns => [1,3,5,7,9])
> shell_out('hogehgoe')
Errno::ENOENT: No such file or directory - hogehgoe
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout/unix.rb:268:in `exec'
> result = shell_out!('ps | grep hogehgoe')
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of ps | grep hogehgoe ----
STDOUT:
STDERR:
---- End output of ps | grep hogehgoe ----
Ran ps | grep hogehgoe returned 1
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.2.0/lib/mixlib/shellout.rb:251:in `invalid!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment