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

后端 未结 5 666
梦如初夏
梦如初夏 2021-01-12 16:27

My demo.rb:

puts ARGV.size

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

The result depends on how we run a script:

>          


        
相关标签:
5条回答
  • 2021-01-12 16:39

    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.

    0 讨论(0)
  • 2021-01-12 16:43

    Open a command window:

    assoc .rb
    

    is it rbFile?

    ftype rbFile
    

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

    the %* is sometimes missing.

    0 讨论(0)
  • 2021-01-12 16:43

    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.

    0 讨论(0)
  • 2021-01-12 16:48

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

    0 讨论(0)
  • 2021-01-12 17:06
    C:\Temp> ftype | grep ruby
    rbFile="c:\opt\ruby\bin\ruby.exe" "%1" %*
    rbwFile="c:\opt\ruby\bin\rubyw.exe" "%1" %*
    
    0 讨论(0)
提交回复
热议问题