2012-03-23 3 views

답변

0

당신은 (리눅스에서) 더 일반적인 솔루션을 원하는 경우 :

require "open3" 

def File.sys_file_cmd(path) 
    if File.exist? path 
     stdin,stdout,stderr = Open3.popen3(%{file --mime -b "#{path}"}) 

     file_err = stderr.gets 
     file_out = stdout.gets 

     if file_err 
     raise Exception, "The 'file' command error: #{file_err} : with #{path}" 
     end 

     if file_err.nil? && (!file_out.nil? && !file_out.empty?) 
     return file_out.split(";")[0].strip 
     end 
    end 

    return nil 
    end 
관련 문제