rubyscript2exe 打包ruby application

拓拔泉
2023-12-01
用rubyscript2exe 把一个ruby 程序变成exe 文件

1,下载rubyscript2exe.rb 文件
http://github.com/cowlibob/rubyscript2exe.git ,从这里下载的能用。
其它的有个错误
修改也可以: 621:
$0.replace(File.expand_path("./init.rb")) 改成 $_0 = File.expand_path("./init.rb")

2, 直接运行 ruby rubyscript2exe.rb xx.rb
........waiting
你就能得到一个xx.exe

这是我写一个确定xml file 的header encoding 和文件内部encoding 是否相符的程序
里面用到
require 'csv'
require 'nokogiri'
require 'UniversalDetector'
所以先要安装一下
windows
gem install nokogiri
gem install rchardet
linux
sudo apt-get install libxslt1-dev libxml2-dev
sudo gem install nokogiri
sudo gem install rchardet
直接上文件:


require 'rubygems'
require 'csv'
require 'nokogiri'
require 'rchardet'
if(ARGV.size ==0 || (!File.directory? ARGV[0]))
puts "Please give me a folder url."
url=gets.strip
if(!File.directory? url)
puts "Please give me a right folder url."
exit
end
else
url = ARGV[0]#"/home/dermot/screenshots/clientA/projectA/"
end
File.delete(url.split('/').join('_')+".csv") if File.exist?(url.split('/').join('_')+".csv")
csv_file = CSV.open(url.split('/').join('_')+".csv","w")
csv_file << ["filename","isWellFormed","bomEncoding","headerEncoding","matched"]
def get_info(url)
str = File.read(url)
bom_encoding = CharDet.detect(str)["encoding"]
#is_bom = get_bom(str)
doc=Nokogiri::XML.parse(str)
header_encoding = doc.encoding
#doc.xpath("//p").collect(&:text).to_s
matched = (bom_encoding.include?(header_encoding)) ? "yes" : "no"
is_well_formed = confirm_form(str)
return is_well_formed,bom_encoding,header_encoding,matched

end
def get_bom(data)
if data[0,3] == "\xEF\xBB\xBF":
# EF BB BF UTF-8 with BOM
#@result = {"encoding"=> "UTF-8", "confidence"=> 1.0}
return "UTF-8_BOM"
elsif data[0,4] == "\xFF\xFE\x00\x00":
# FF FE 00 00 UTF-32, little-endian BOM
#@result = {"encoding"=> "UTF-32LE", "confidence"=> 1.0}
return "UTF-32LE_BOM"
elsif data[0,4] == "\x00\x00\xFE\xFF":
# 00 00 FE FF UTF-32, big-endian BOM
#@result = {"encoding"=> "UTF-32BE", "confidence"=> 1.0}
return "UTF-32BE_BOM"
elsif data[0,4] == "\xFE\xFF\x00\x00":
# FE FF 00 00 UCS-4, unusual octet order BOM (3412)
#@result = {"encoding"=> "X-ISO-10646-UCS-4-3412", "confidence"=> 1.0}
return "X-ISO-10646-UCS-4-3412_unusual_BOM"
elsif data[0,4] == "\x00\x00\xFF\xFE":
# 00 00 FF FE UCS-4, unusual octet order BOM (2143)
#@result = {"encoding"=> "X-ISO-10646-UCS-4-2143", "confidence"=> 1.0}
return "X-ISO-10646-UCS-4-2143_unusual_BOM"
elsif data[0,2] == "\xFF\xFE":
# FF FE UTF-16, little endian BOM
#@result = {"encoding"=> "UTF-16LE", "confidence"=> 1.0}
return "UTF-16LE_BOM"
elsif data[0,2] == "\xFE\xFF":
# FE FF UTF-16, big endian BOM
#@result = {"encoding"=> "UTF-16LE", "confidence"=> 1.0}
return "UTF-16LE_BOM"
end
return "no"
end
def confirm_form(str)
begin
Nokogiri::XML(str){|config| config.options=Nokogiri::XML::ParseOptions::STRICT}
rescue
return "no"
end
return "yes"
end
def walk_dir(path,csv_file )
dir = Dir.new(path)
dir.find_all do |file|
if (file != "." && file != "..")
url = path+File::SEPARATOR+file
if (File.directory? url)
walk_dir(url,csv_file )
elsif (!(/\.xml$/=~file).nil?)
csv_file << [url]+get_info(url)
end
end
end
end
walk_dir(url,csv_file )
csv_file.close
puts "finished"

想做成 gui的,可是没找到ruby类似filedialog 的组件,有知道的可以告诉下,3xu~!
 类似资料: