Ruby ARGV may be empty for windows depending on how the script is run

My demo.rb:

puts ARGV.size ARGV.each do |a| puts "Argument: #{a}" end 

The result depends on how we run the script:

 > demo.rb foo bar 0 > ruby demo.rb foo bar 2 Argument: foo Argument: bar 

Why is this happening? And is there anything you can do about it?

EDIT: Thanks everyone! Here are my settings:

 >assoc .rb .rb=rbFile >ftype rbFile rbFile="c:\ruby-1.8.6\bin\ruby.exe" "%1" %* 

So it looks right.

But I found that

 >demo.rb foo bar 

starts the process with the following command line:

 "C:\ruby-1.8.7\bin\ruby.exe" "c:\demo.rb" 

Note that .rb is associated with 1.8.6, but 1.8.7 starts.

So, I think something else went bad?

+6
ruby argv
source share
5 answers

Open a command prompt window:

 assoc .rb 

is it rbFile?

 ftype rbFile 

Make sure Ruby.exe is followed by "% 1"% *

sometimes missing% *.

+8
source share
  C: \ Temp> ftype |  grep ruby
 rbFile = "c: \ opt \ ruby ​​\ bin \ ruby.exe" "% 1"% *
 rbwFile = "c: \ opt \ ruby ​​\ bin \ rubyw.exe" "% 1"% *
+3
source share

Check file association. Especially in advanced settings, see the "Open" action. Make sure there is% * at the end of the action.

This question is about the powershell question, but it is essentially the same question, so my answer there should give a little more detailed information.

+2
source share

It seems that the arguments are not passed to the ruby ​​interpreter in your association with the file type. See this section on how the association should look and confirm yours.

+1
source share

You can use the free tool from Nirsoft - FileTypesManager - add the missing %* , as indicated in other posts.

0
source share

All Articles