Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows command line args getting to Ruby program only if explicitly invoked as "ruby" [duplicate]

Tags:

ruby

argv

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?

like image 716
alex2k8 Avatar asked Feb 06 '26 12:02

alex2k8


1 Answers

Open a command window:

assoc .rb

is it rbFile?

ftype rbFile

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

the %* is sometimes missing.

like image 85
Jonas Elfström Avatar answered Feb 09 '26 04:02

Jonas Elfström



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!