文件是 windows 中创建的,带\r\n,每次上传到 linux 下都要 dos2unix 才能使用,想到了替换,但这样操作不成功,是没有回写么? File.open("#{path}/#{filename}.dat").each_line {|str| str.gsub!(/"\r\n"/,"\n")}
一是替换没写对,二是没回写
s = File.binread("#{path}/#{filename}.dat").gsub "\r\n", "\n"
File.open(s, 'wb'){|f| f << s }
换个好点的编辑器,设置换行模式为 unix 的就不会再产生这个了
#15 楼 @luikore s = File.read("#{path}/#{filename}.dat").gsub(/"\r\n"/,"\n") File.open(s,"w"){|f| f << s }
1) Error: test_create_authinfo_log(TestAreaCenterClientOperation): Errno::EINVAL: Invalid argument - 491899858 00:05:00 1 2 2 90000 |21:1| 2 3158984320 00:05:00 1 2 2 90000 |21:1| 2 2 85000 |10000:5| 3508624407 00:05:00 1 2 2 90000 |21:1| 2 2 85000 |10000:5|
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:60:in initialize'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:60:in
open'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:60:in create_authinfo_log'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:50:in
times'
C:/operator/keywords/keyword/area_center/area_center_client_operation.rb:50:in create_authinfo_log'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/1.8/delegate.rb:159:in
send'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/1.8/delegate.rb:159:in method_missing'
C:/ATT_rake_server_ruby187/ruby/lib/ruby/gems/1.8/gems/att-1.1.0/lib/att/keyword_manager.rb/../../att/t
test_area_center_client_operation.rb:16:in
test_create_authinfo_log'
不好意思写错了... 把文件的内容放到文件名那里了...
full_path = "#{path}/#{filename}.dat"
s = File.binread(full_path).gsub "\r\n", "\n"
File.open(full_path, 'wb'){|f| f << s }
P.S. 另外仔细看啊,是 gsub "\r\n", "\n"
不是 gsub /"\r\n"/, "\n"