0
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。我錯了什麼?IO錯誤:在irb中關閉流
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>'
爲我工作,,,! –
請參閱[這裏](http://www.ruby-doc.org/core-1.9.3/IOError.html),以瞭解何時會出現這樣的錯誤。但我沒有看到任何此類症狀你的代碼。 –
文件'「/ tmp/test」'是否存在? –