由於某種原因,我的紅寶石出現卡住,我無法弄清楚爲什麼, 我通過反引號傳遞的命令是正常的,腳本卡在puts 2和put 2命令之間,因此,它基本上不退出puts命令包含了Unix排序/切 #在/ usr/bin中/紅寶石/ruby put get stuck添加unix內容
require 'fileutils'
@raw_file=File.open(ARGV[0],"r") unless File.open(ARGV[0],"r").nil?
#agg_file=File.open(ARGV[1],"r") unless File.open(ARGV[1],"r").nil?
@pwd=Dir.pwd
puts @pwd
#do the raw file first
def do_raw
tmp_raw=File.new("#{@pwd}/tmp_raw","w")
#unix cut and sort
puts 1
tmp_raw.puts(`cat #{@raw_file} | cut -f1,6,3,4,2,5,9,12 | sort -k1,1 -k8,8`)
puts 2
tmp_raw.close
tmp_raw=File.open("#{@pwd}/tmp_raw","r")
final_file=File.new("#{@pwd}/uniques_raw","w")
#merge the lines and append count
vector =IO.readlines(@tmp_raw.path)[1]
count=1
while (line=tmp_raw.gets) do
if line.eql? vector
count=count+1
else
vector=line
final_file.write("#{line}\t#{count}")
count=1
end
end
#job done, close and clean file
tmp_raw.close
final_file.close
tmp_raw.remove
end
#run jobs
do_raw
但是一個簡單的: tmp_raw.puts( 「blablabla」) 作品,所以文件是好的
puts命令卡住了,我試了一下簡單的comman D在終端上,它工作得很好,文件也存在,並寫入一些隨機文本到他們的作品很好 任何想法?
我想'tmp_raw.close'可能將刷新內容是什麼? – bsd
thx,但不幸的是,它不會,它真的永遠不會出現在puts命令中,我添加了一個永不打印的puts「2」命令.... – JBoy
什麼是@ raw_puts。它應該是'@ raw_file' – bsd