Ruby 的 ARGV 在 Windows 上可以为空,具体取决于运行脚本的方式 [英] Ruby's ARGV can be empty on windows depending on a way to run script
本文介绍了Ruby 的 ARGV 在 Windows 上可以为空,具体取决于运行脚本的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 demo.rb:
My demo.rb:
puts ARGV.size
ARGV.each do |a|
puts "Argument: #{a}"
end
结果取决于我们如何运行脚本:
The result depends on how we run a script:
> demo.rb foo bar
0
> ruby demo.rb foo bar
2
Argument: foo
Argument: bar
为什么会这样?可以用这个做些什么吗?
Why this happens? And can some thing be done with this?
感谢所有回复!这是我的设置:
Thanks to all replies! Here my settings:
>assoc .rb
.rb=rbFile
>ftype rbFile
rbFile="c:\ruby-1.8.6\bin\ruby.exe" "%1" %*
所以看起来是对的.
但是我发现
>demo.rb foo bar
使用这样的命令行启动进程:
starts process with such Command Line:
"C:\ruby-1.8.7\bin\ruby.exe" "c:\demo.rb"
请注意,.rb 与 1.8.6 相关联,但 1.8.7 已启动.
Notice, that .rb associated with 1.8.6, but 1.8.7 is started.
所以我猜是不是还有什么事情搞砸了?
So I guess some thing else is messed up?
推荐答案
打开命令窗口:
assoc .rb
是 rbFile 吗?
is it rbFile?
ftype rbFile
确保 Ruby.exe 后跟%1"%*
Make sure that Ruby.exe is followed by "%1" %*
%* 有时会丢失.
这篇关于Ruby 的 ARGV 在 Windows 上可以为空,具体取决于运行脚本的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文