Ruby: irb doesn't work on Windows

前端 未结 3 1303
轻奢々
轻奢々 2021-01-15 03:30

I\'ve installed Ruby 1.93 in my windows 7 PC using Ruby 1.9.3-p194 one click installer. I can use ruby command to interpret files, but when I type irb

相关标签:
3条回答
  • 2021-01-15 04:00

    I got the solution from Pete's comment. I have Cygwin installed in my computer which was causing the problem (Not sure why). I have just typed this in the command line: set HOME= and irb started working!

    You can also see this link.

    0 讨论(0)
  • 2021-01-15 04:02

    I'd suggest to use DevKit. I have 64-bit Windows 7 and ruby 1.9.3-p125, and everything works smoothly with DevKit.

    d:\>systeminfo | findstr /B /C:"OS Name"
    OS Name:                   Microsoft Windows 7 Enterprise
    
    d:\>ruby -v
    ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
    
    d:\>irb
    irb(main):001:0> 2+2
    => 4
    irb(main):002:0> exit
    
    0 讨论(0)
  • 2021-01-15 04:10

    If you have problem to start IRB in Ruby 1.9.3 related to fiddle you can do this:

    In rubyxxx\lib\ruby\site_ruby\x.x.x\rbreadline.rb replace:

    This:

      require 'fiddle'
      class Win32API
        DLL = {}
        TYPEMAP = {"0" => Fiddle::TYPE_VOID, "S" => Fiddle::TYPE_VOIDP, "I" => Fiddle::TYPE_LONG}
        CALL_TYPE_TO_ABI = {:stdcall => 1, :cdecl => 1, nil => 1} #Taken from Fiddle::Importer
    
        def initialize(dllname, func, import, export = "0", calltype = :stdcall)
          @proto = import.join.tr("VPpNnLlIi", "0SSI").chomp('0').split('')
          handle = DLL[dllname] ||= Fiddle.dlopen(dllname)
          @func = Fiddle::Function.new(handle[func], TYPEMAP.values_at(*@proto), CALL_TYPE_TO_ABI[calltype])
        end
    
        def call(*args)
          args.each_with_index do |x, i|
            args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if @proto[i] == "S"
            args[i], = [x].pack("I").unpack("i") if @proto[i] == "I"
          end
          @func.call(*args).to_i || 0
        end
    

    With:

      require 'dl'
      class Win32API
        DLL = {}
        TYPEMAP = {"0" => DL::TYPE_VOID, "S" => DL::TYPE_VOIDP, "I" => DL::TYPE_LONG}
    
        def initialize(dllname, func, import, export = "0", calltype = :stdcall)
          @proto = [import].join.tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
          handle = DLL[dllname] ||= DL.dlopen(dllname)
          @func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, calltype)
        end
    
        def call(*args)
          import = @proto.split("")
          args.each_with_index do |x, i|
            args[i], = [x == 0 ? nil : x].pack("p").unpack("l!*") if import[i] == "S"
            args[i], = [x].pack("I").unpack("i") if import[i] == "I"
          end
          ret, = @func.call(args)
          return ret || 0
        end
    
    0 讨论(0)
提交回复
热议问题