[英]Ruby: irb doesn't work on Windows
I've installed Ruby 1.93 in my windows 7 PC using Ruby 1.9.3-p194 one click installer. 我已经使用Ruby 1.9.3-p194一键安装程序在Windows 7 PC中安装了Ruby 1.93。 I can use
ruby
command to interpret files, but when I type irb
it gives me the following error: 我可以使用
ruby
命令来解释文件,但是当我输入irb
,会出现以下错误:
C:\Users\Acer>irb
F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2111:in `expand_path': non-absolute home
(ArgumentError)
from F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2111:in `_rl_read_init_file'
from F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2094:in `rl_read_init_file'
from F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2515:in `readline_initialize
_everything'
from F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/rbreadline.rb:3746:in `rl_initialize'
from F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4758:in `readline'
from F:/Programs/Ruby193/lib/ruby/site_ruby/1.9.1/readline.rb:40:in `readline'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top
_level_statement'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_stat
ement'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:70:in `block in start'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:69:in `catch'
from F:/Programs/Ruby193/lib/ruby/1.9.1/irb.rb:69:in `start'
from F:/Programs/Ruby193/bin/irb:12:in `<main>'
I installed Ruby on F:/Programs/Ruby193
folder and added F:/Programs/Ruby193/bin
in my PATH
. 我在
F:/Programs/Ruby193
文件夹中安装了Ruby,并在PATH
添加了F:/Programs/Ruby193/bin
。 I also tried with Ruby 1.87 but got the same error. 我也尝试使用Ruby 1.87,但出现了相同的错误。
I got the solution from Pete's comment. 我从Pete的评论中得到了解决方案。 I have
Cygwin
installed in my computer which was causing the problem (Not sure why). 我在计算机上安装了
Cygwin
,这引起了问题(不确定原因)。 I have just typed this in the command line: set HOME=
and irb
started working! 我刚刚在命令行中输入了此命令:
set HOME=
并且irb
开始工作!
If you have problem to start IRB in Ruby 1.9.3 related to fiddle you can do this: 如果您在与小提琴相关的Ruby 1.9.3中启动IRB遇到问题,可以执行以下操作:
In rubyxxx\\lib\\ruby\\site_ruby\\xxx\\rbreadline.rb
replace: 在
rubyxxx\\lib\\ruby\\site_ruby\\xxx\\rbreadline.rb
替换:
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
I'd suggest to use DevKit . 我建议使用DevKit 。 I have 64-bit Windows 7 and ruby 1.9.3-p125, and everything works smoothly with DevKit.
我有64位Windows 7和ruby 1.9.3-p125,并且所有东西都可以在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.