IOError:irb中的封闭流

时间:2013-11-09 18:27:52

标签: ruby file-io io irb ioerror

File.open("/tmp/test") do |file|
  file.each_line("e") {|line|
    puts "Got #{ line.dump }"
  }
end

在irb中返回“IOError:closed stream”。但如果是保存在文件'test.rb'中,ruby test.rb - 工作正常。 Ruby版本:ruby-2.0.0-p247,ruby-2.1.0-preview1,Ubuntu,Mac OS。我错了什么?

user:ads user$ echo "a\nb\nc" > /tmp/test
user:ads user$ irb
2.1.0-preview1 :001 > File.open("/tmp/test") { |file| file.each_line { |line| puts "Got #{ line.dump }" } }
Got "a\\nb\\nc\n"
IOError: closed stream
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/formatter.rb:199:in `directory?'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/formatter.rb:199:in `awesome_file'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/formatter.rb:26:in `format'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/inspector.rb:137:in `unnested'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/inspector.rb:104:in `awesome'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/kernel.rb:10:in `ai'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/kernel.rb:20:in `ap'
    from /Users/user/.irbrc:7:in `output_value'
    from /Users/user/.rvm/rubies/ruby-2.1.0-preview1/bin/irb:15:in `<main>'

1 个答案:

答案 0 :(得分:0)

https://github.com/michaeldv/awesome_print/pull/141

中的可能修复方法
- ls = File.directory?(f) ? `ls -adlF #{f.path.shellescape}` : `ls -alF #{f.path.shellescape}`
+ ls = `ls -adlF #{f.path.shellescape}`