来自 ruby 内核系统的自制软件



我正在尝试从红宝石脚本中发出一个自动壳命令。

我可以发布自制外壳命令。例如,这无问题:

$ brew list | head -n 1
ack

我也可以从Ruby发出shell命令:

$ bundle exec ruby -e "Kernel.system('echo foo')"
foo

但是,当我从Ruby发出Homebrew Shell命令时,我会收到与Bundler相关的错误:

bundle exec ruby -e "Kernel.system('brew list')"
Your bundle is locked to bubs (0.0.6), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of bubs (0.0.6) has removed it. You'll need to update your bundle to a different version of bubs (0.0.6) that hasn't been removed in order to install.

即使是最小的gemfile(哪个宝石没关系)也会发生这种情况。

source 'https://rubygems.org'
gem 'bubs'

所以,一部分Homebrew,Ruby,Bundler,也许是RVM(这是我的Ruby当前安装的方式)都不好。

知道为什么我可能会遇到此错误,/或我如何从Ruby中工作?

在搜索后找到答案:包裹您在 Bundler.with_clean_env中的捆绑器中进行的任何炮击。例如: bundle exec ruby -e "Bundler.with_clean_env { Kernel.system('brew list') }"将起作用。

Bundler提供了类似物品的快捷方式:Bundler.clean_system('brew list')

来自文档:http://bundler.io/v1.13/man/bundle-exec.1.html#shelling-und

最新更新