Ruby的ARGV在Windows上可以为空,具体取决于运行脚本的方式 [英] Ruby's ARGV can be empty on windows depending on a way to run script
本文介绍了Ruby的ARGV在Windows上可以为空,具体取决于运行脚本的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的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吗?
ftype rbFile
确保Ruby.exe后跟%1"%*
Make sure that Ruby.exe is followed by "%1" %*
%*有时会丢失.
这篇关于Ruby的ARGV在Windows上可以为空,具体取决于运行脚本的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文