Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby “为什么?”;bundle exec“;吃我传递的参数?_Ruby_Gem_Exec_Bundle_Bundler - Fatal编程技术网

Ruby “为什么?”;bundle exec“;吃我传递的参数?

Ruby “为什么?”;bundle exec“;吃我传递的参数?,ruby,gem,exec,bundle,bundler,Ruby,Gem,Exec,Bundle,Bundler,当我使用bundle exec调用命令时,它接受我传入的参数。例如: bundle exec my_command run --verbose 在本例中,--verbose用作绑定器参数,其中as应用于my_命令。我知道以下方法可行: bundle exec 'my_command run --verbose' 可以避免引用吗?我使用的命令已经有很多引号了。我原以为这样做会奏效,但没有: bundle exec -- my_command run --verbose 我没有看到关于bund

当我使用
bundle exec
调用命令时,它接受我传入的参数。例如:

bundle exec my_command run --verbose
在本例中,
--verbose
用作绑定器参数,其中as应用于
my_命令
。我知道以下方法可行:

bundle exec 'my_command run --verbose'
可以避免引用吗?我使用的命令已经有很多引号了。我原以为这样做会奏效,但没有:

bundle exec -- my_command run --verbose
我没有看到关于bundler的很多文档。任何想法都将不胜感激。

从中查看,默认行为是将
bundle exec
之后的所有参数传递给
Kernel.exec
,因此
--verbose
参数将传递给您的命令,而不是
bundle

bundle exec my_command run --verbose
将在bundle的上下文中运行以下命令

Kernel.exec('my_command', 'run', '--verbose')

由于未命名任何命令/脚本--,因此导致错误

在此处检查测试用例:

#!/usr/bin/env ruby
# coding: utf-8
# file: test.rb

p ARGV
测试:


这看起来像是在shell中将一个命令传递给另一个命令时的常见问题,而且看起来您已经接近我所使用的了。而不是使用:

bundle exec my_command run --verbose
或:

尝试:


使用
bundle exec--
会中断
bundle exec的命令链
exec
bundle
的子命令,
my_command
exec
的参数。
my_命令的参数
,无论是
bundle
还是
exec
都不需要知道它们,因此
--
都会转到您想要断开参数链到
bundle

的地方。我没有这个问题,您使用的bundler版本是什么?例如,我使用的是bundler版本1.3.5,运行特定的ActiveSupport::TestCase
bundle exec ruby--test/unit/class_test.rb-n'/test_a_method/'
$ bundle exec ruby test.rb --verbose --arg1
["--verbose", "--arg1"]
bundle exec my_command run --verbose
bundle exec -- my_command run --verbose
bundle exec my_command -- run --verbose