开发者_运维知识库This isn't working in ruby and I don't understand why?
#!/usr/bin/env ruby
exec "sort data.txt > data.sort"
data.txt is a comma sepparated file. Anyway.. If I try to execute that line in the shell it works without a problem.
When I try to run this script from my script, I get an empty file.
This isn't really an answer, but I wanted to share that your original usage of exec is actually working for me. This was how I set it up.
data.txt
"1,2,3,4,5,6,7,8"
sort.rb (I don't know what your sort did so I am just writing the same data out)
File.open(ARGV[0]){|f| puts f.read}
irb session
irb(main):001:0> exec "sort data.txt > data.sort"
When I ran this in irb, I did get a data.sort output file and it contained "1,2,3,4,5,6,7,8" as expected. I can run the same exec line through irb or from another ruby file, and I get the output file with data each time.
I am running Ruby 1.8.6 on a 32bit Windows XP system.
Have you tried
%x(sort data.txt > data.sort)
精彩评论