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

should_run_under_cmd? fails on windows when argument is an array #154

Closed
skylerto opened this issue Apr 26, 2018 · 5 comments
Closed

should_run_under_cmd? fails on windows when argument is an array #154

skylerto opened this issue Apr 26, 2018 · 5 comments

Comments

@skylerto
Copy link

This issue comes from something discovered in chef-cookbooks/habitat PR.

When using similar to the following:

shell_out_with_timeout!(clean_array('hab', ['pkg', 'path', 'skylerto/splunkforwarder']))
NoMethodError
-------------
undefined method `each_char' for ["hab", "pkg", "path", "skylerto/splunkforwarder"]:Array
Did you mean?  each
    each_cons

and debug stacktrace:

C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/mixlib-shellout-2.2.7-universal-mingw32/lib/mixlib/shellout/windows.rb:266:in `should_run_under_cmd?'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/mixlib-shellout-2.2.7-universal-mingw32/lib/mixlib/shellout/windows.rb:191:in `command_to_run'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/mixlib-shellout-2.2.7-universal-mingw32/lib/mixlib/shellout/windows.rb:59:in `run_command'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/mixlib-shellout-2.2.7-universal-mingw32/lib/mixlib/shellout.rb:259:in `run_command'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/mixin/shell_out.rb:191:in `shell_out_command'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/mixin/shell_out.rb:112:in `shell_out'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/mixin/shell_out.rb:117:in `shell_out!'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/provider/package.rb:637:in `shell_out_with_timeout!'
  C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/habitat/libraries/provider_hab_package.rb:90:in `hab'
  C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/habitat/libraries/provider_hab_package.rb:144:in `installed_version'
  C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/habitat/libraries/provider_hab_package.rb:139:in `block in current_versions'
  C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/habitat/libraries/provider_hab_package.rb:138:in `map'
  C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/habitat/libraries/provider_hab_package.rb:138:in `current_versions'
  C:/Users/vagrant/AppData/Local/Temp/kitchen/cache/cookbooks/habitat/libraries/provider_hab_package.rb:59:in `load_current_resource'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/provider.rb:128:in `run_action'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource.rb:622:in `run_action'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/runner.rb:69:in `run_action'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/runner.rb:97:in `block (2 levels) in converge'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/runner.rb:97:in `each'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/runner.rb:97:in `block in converge'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/runner.rb:96:in `converge'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/client.rb:715:in `block in converge'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/client.rb:710:in `catch'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/client.rb:710:in `converge'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/client.rb:749:in `converge_and_save'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/client.rb:286:in `run'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application.rb:277:in `run_with_graceful_exit_option'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application.rb:253:in `block in run_chef_client'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/local_mode.rb:44:in `with_server_connectivity'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application.rb:236:in `run_chef_client'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application/client.rb:464:in `sleep_then_run_chef_client'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application/client.rb:451:in `block in interval_run_chef_client'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application/client.rb:450:in `loop'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application/client.rb:450:in `interval_run_chef_client'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application/client.rb:434:in `run_application'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/lib/chef/application.rb:59:in `run'
  C:/opscode/chef/embedded/lib/ruby/gems/2.3.0/gems/chef-12.20.3-universal-mingw32/bin/chef-client:26:in `<top (required)>'
  C:/opscode/chef/bin/chef-client:68:in `load'
  C:/opscode/chef/bin/chef-client:68:in `<main>'
@coderanger
Copy link
Contributor

coderanger commented Apr 26, 2018

Unfortunately there isn't really a clear semantic as to what running an array command should mean on Windows. There is no direct analogue as command lines are inherently string-y on Windows. Simulating the Unix behavior depends on what parser the command is using, though most follow the same conventions. See also: https://github.com/poise/poise/blob/ef560c82971b727f81aae3c9e36b1251848de14b/lib/poise/utils/win32.rb#L59-L100

@skylerto
Copy link
Author

hmm, I guess it's not as straight forward as I thought (joining the array into a sting) on windows.

@coderanger
Copy link
Contributor

That is certainly an option, but wouldn't really have the same behavior as on Unix :) I would definitely like to see this improved, and lifting my code from poise into core is definitely an option, but there was some concern over the level of magic so we probably want something similar but maybe 5% less magic.

@skylerto
Copy link
Author

This looks like it will solve the problem! What was the reason that this isn’t in core — I hope magic wasn’t the reason. 😛

@lamont-granquist
Copy link
Contributor

This is a dup basically of #125

mixlib-shellout currently does not support array style arguments on windows. period. full stop.

i made a run before at pulling noah's fixes into mixlib-shellout but failed due to some edge cases that we have tests for here in mixlib-shellout failing and being unable to turn them green.

the full story of how utterly idiotic quoting cli stuff in windows is here:

https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/

fixing #125 is not trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants