【问题标题】:Unable to pass command line arguments in Ruby 2.0.0无法在 Ruby 2.0.0 中传递命令行参数
【发布时间】:2017-11-07 03:26:26
【问题描述】:

我刚刚在 Windows 7 上安装了 Ruby 2.0.0(使用“rubyinstaller-2.0.0-p247-x64.exe”)。我认为文件关联还可以:

$> assoc .rb
.rb = rbfile

$> ftype rbfile
rbfile="C:\Ruby200-x64\bin\ruby.exe" "%1" %*

但是,我无法将任何参数传递给解释器。

所以如果我运行一个简单的脚本(test.rb):

puts ARGV[0]

它什么也没给:

>test.rb test1
>

我想我应该补充一点,直到昨天我还安装了 Ruby 1.9.3。我卸载了它,并安装了上面的(Ruby 2.0.0)。过去在 Ruby 1.9.3 中一切正常。

请帮忙!!

谢谢。

【问题讨论】:

  • 你为什么要重复 assoc?你有两次.rbrbfile
  • 对不起,这是我第一次发布问题,我不知道如何正确格式化它。我现在已经更正了。
  • 是的,.rb 脚本被识别,并且工作正常(例如,“puts hello”输出“hello”),但是命令行参数没有被传递。 assoc 和 ftype 显示了正确的内容,如上所述。
  • 我知道这并没有什么不同,但如果没有更好的答案,请查看:techotopia.com/index.php/…

标签: ruby windows


【解决方案1】:

其他人过去曾使用 Vista 和 Ruby 1.9 similar problems。这似乎与手动修改或旧版本卸载失败有关。

在 Windows 7 上全新安装“rubyinstaller-2.0.0-p247-x64.exe”对我有用。 assocftype 命令了解 ruby​​。

> assoc .rb
File association not found for extension .rb

> ftype rbfile
File type 'rbfile' not found or no open command associated with it.

我建议您通过以管理员身份启动 Shell 并运行 ftype rbfile=assoc .rb= 来取消设置这些值。如果这没有帮助(进行备份并)删除所有包含rbfile 的注册表项。正确的密钥使用RubyFileRubyWFileInnoSetup Script 包含正确的注册表项。

【讨论】:

  • 我取消了 ftype rbfile 和 assoc .rb 的值,全新安装了 32 位版本,重新设置了 assoc .rb 和 ftype rbfile 关联,它成功了!所以我现在要坚持下去。
【解决方案2】:

在 Windows 7 中为我工作:

  • 运行注册表
  • 找到 HKEY_CLASSES_ROOT\Applications\ruby.exe\shell\open\command
  • 确保“(默认)”条目显示: (默认) REG_SZ "C:\Ruby21-x64\bin\ruby.exe" "%1" %* 当我检查时,我的 %* 丢失了。 当然,ruby 路径必须与 ruby​​ 的安装位置匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-10
    • 2016-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    • 2012-07-11
    相关资源
    最近更新 更多