Domanda

My ruby puts get stuck for some reason and i cant figure out why, The commands i'm passing through the backticks are alright, the script gets stuck between the puts 2 and puts 2 commands, so it basically never exits the puts command containing the unix sort / cut #!/usr/bin/ruby/

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

But a simple: tmp_raw.puts("blablabla") Works, so the file is ok

The puts command get stuck, i have tryed the simple command on terminal and it works just fine, the files are also existing and writing some random text into them works just fine Any idea?

È stato utile?

Soluzione

I see. @raw_file is a File object rather than the file name itself. Then you cannot invoke the cat(1) command against the string representation of the File object.

You should have wrote

tmp_raw.puts(`cat #{ARGV[0]} | cut -f1,6,3,4,2,5,9,12 | sort -k1,1 -k8,8`)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top