Last active
August 29, 2015 13:57
-
-
Save sawanoboly/9907848 to your computer and use it in GitHub Desktop.
Chefの`shell_out`と`shell_out!`、違いと使い分け ref: http://qiita.com/sawanoboly/items/43bc9e15739355f9c533
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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