Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell_out without a bang can fail if there's no shell metacharacters and the file does not exist #162

Open
lamont-granquist opened this issue Jul 6, 2018 · 0 comments
Labels
Type: Bug Does not work as expected.

Comments

@lamont-granquist
Copy link
Contributor

[1] pry(main)> require 'chef/mixin/shell_out'
=> true
[2] pry(main)> include Chef::Mixin::ShellOut
=> Object
[3] pry(main)> shell_out("lskdjflskj 'foo'")
=> <Mixlib::ShellOut#70318079326640: command: 'lskdjflskj 'foo'' process_status: #<Process::Status: pid 4874 exit 127> stdout: '' stderr: 'sh: lskdjflskj: command not found' child_pid: 4874 environment: {"LC_ALL"=>"en_US.UTF-8", "LANGUAGE"=>"en_US.UTF-8", "LANG"=>"en_US.UTF-8", "PATH"=>"/Users/lamont/.rvm/gems/ruby-2.5.1/bin:/Users/lamont/.rvm/gems/ruby-2.5.1@global/bin:/Users/lamont/.rvm/rubies/ruby-2.5.1/bin:/opt/chefdk/bin:/Users/lamont/.chefdk/gem/ruby/2.5.0/bin:/opt/chefdk/embedded/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/lamont/bin:/usr/local/sbin:/opt/chefdk/gitbin:/Users/lamont/.rvm/bin"} timeout: 600 user:  group:  working_dir:  >
[4] pry(main)> shell_out("lskdjflskj")
Errno::ENOENT: No such file or directory - lskdjflskj
from /Users/lamont/.rvm/gems/ruby-2.5.1/gems/mixlib-shellout-2.3.2/lib/mixlib/shellout/unix.rb:340:in `exec'

The second case should probably catch Errno::ENOENT and remap it onto the same error message you get from calling error!:

[5] pry(main)> shell_out("lskdjflskj 'foo'").error!
Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '127'
---- Begin output of lskdjflskj 'foo' ----
STDOUT:
STDERR: sh: lskdjflskj: command not found
---- End output of lskdjflskj 'foo' ----
Ran lskdjflskj 'foo' returned 127
from /Users/lamont/.rvm/gems/ruby-2.5.1/gems/mixlib-shellout-2.3.2/lib/mixlib/shellout.rb:293:in `invalid!'
@tas50 tas50 added the Type: Bug Does not work as expected. label Oct 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Does not work as expected.
Projects
None yet
Development

No branches or pull requests

2 participants