Ruby's ARGV can be empty on windows depending on a way to run script
Asked Answered
T

5

6

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?

EDIT: Thanks to all replies! Here my settings:

>assoc .rb
.rb=rbFile

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

So it looks right.

But I have discovered that

>demo.rb foo bar

starts process with such Command Line:

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

Notice, that .rb associated with 1.8.6, but 1.8.7 is started.

So I guess some thing else is messed up?

Tko answered 27/8, 2009 at 13:48 Comment(0)
A
8

Open a command window:

assoc .rb

is it rbFile?

ftype rbFile

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

the %* is sometimes missing.

Awash answered 27/8, 2009 at 13:56 Comment(0)
A
3
C:\Temp> ftype | grep ruby
rbFile="c:\opt\ruby\bin\ruby.exe" "%1" %*
rbwFile="c:\opt\ruby\bin\rubyw.exe" "%1" %*
Administrative answered 27/8, 2009 at 13:56 Comment(0)
T
2

Check the file association. Especially in the advanced settings look at the "Open" action. Make sure that there is a %* on the end of the action.

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

Turpeth answered 27/8, 2009 at 13:53 Comment(0)
T
1

Sounds like the arguments are not passed on to the ruby interpreter, in your association of the filetype. See this section for how the association should look, and verify yours.

Tattletale answered 27/8, 2009 at 13:55 Comment(0)
T
0

You can use a freeware tool from Nirsoft - FileTypesManager - to add the missing %* as mentioned in the other posts.

Trinh answered 1/8, 2012 at 7:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.