惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
博客园 - 司徒正美
P
Privacy International News Feed
G
Google Developers Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
K
Kaspersky official blog
I
InfoQ
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
量子位
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
S
Security Affairs
Latest news
Latest news
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
V
Visual Studio Blog
T
Troy Hunt's Blog
S
Secure Thoughts
F
Fortinet All Blogs
V
V2EX
The Register - Security
The Register - Security
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - slaughter

java api下载网站 国外好的软件测试网站 watir,ruby版本查看方法 - slaughter - 博客园 Watir隐藏IE运行的方法 Ruby对MS Access的操作 Eclipse下安装RDT (转)什么是Unicode?什么是UTF-8?(1) Ruby的库路径 - slaughter - 博客园 ruby下snmp-trap发包实例 - slaughter - 博客园 Ruby对于串口的设置实例 - slaughter - 博客园 职业选择(转) ruby编码中碰到的一个诡异问题 - slaughter - 博客园 java读写文件(转) 在Java中操纵UDP(转) 在Java中使用UDP协议编程的相关类(转) 终于给宝宝确定了名字 RFT的对象识别技术 Ruby设置IE不可见 VC对EXCEL操作
Ruby转exe方法(转)
slaughter · 2008-05-06 · via 博客园 - slaughter

1. Exerb简介

Exerb是一个将ruby脚本程序(.rb)转换成Windows应用程序(.exe)的软件。目前最新版本4.1.0,下载地址:http://downloads.sourceforge.jp/exerb/23470/exerb-4.1.0.zip


2.安装

把下载的zip文件解压,进入exerb目录,运行ruby setup.rb。这时exerb和mkexy命令将会加入ruby/bin目录中。

3.ruby -> exe

先来个最简单的

hello.rb

  1. puts 'Exerb'

运行exerb hello.rb,生成一个hello.exe文件,OK。

下面写个GUI程序,使用wxRuby类库。

hello_wx.rb

  1. require 'wxruby'
  2. include Wx
  3. class MyFrame < Frame
  4.    def initialize(title)
  5.      super(nil, -1, title)
  6.      Button.new(self, -1, "Hello, I'm a Button")
  7.    end
  8. end
  9. class MyApp < App
  10.    def on_init
  11.      frame = MyFrame.new('Simple wxRuby App')
  12.      frame.show
  13.    end
  14. end
  15. a = MyApp.new
  16. a.main_loop

exerb hello_wx.rb,生成hello_wx.exe,却不能运行。因为exe并没有把程序所需的类库打包进来,这时候就得执行mkexy命令。

mkexy hello_wx.rb,生成hello_wx.exy文件

hello_wx.exy

  1. # Generated by mkexy
  2. # on 2007-01-31 23:50
  3. general:
  4.   startup: hello_wx.rb
  5.    core: cui
  6.    kcode: none
  7. file:
  8.    hello_wx.rb:
  9.    rbconfig.rb:
  10.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/rbconfig.rb
  11.    rubygems/rubygems_version.rb:
  12.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/rubygems_version.rb
  13.    rbconfig/datadir.rb:
  14.      file: c:/ruby/lib/ruby/site_ruby/1.8/rbconfig/datadir.rb
  15.    rubygems/user_interaction.rb:
  16.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/user_interaction.rb
  17.    forwardable.rb:
  18.      file: c:/ruby/lib/ruby/1.8/forwardable.rb
  19.    digest.so:
  20.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/digest.so
  21.      type: extension-library
  22.    digest/sha2.so:
  23.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/digest/sha2.so
  24.      type: extension-library
  25.    rational.rb:
  26.      file: c:/ruby/lib/ruby/1.8/rational.rb
  27.    date/format.rb:
  28.      file: c:/ruby/lib/ruby/1.8/date/format.rb
  29.    parsedate.rb:
  30.      file: c:/ruby/lib/ruby/1.8/parsedate.rb
  31.    time.rb:
  32.      file: c:/ruby/lib/ruby/1.8/time.rb
  33.    rubygems/source_index.rb:
  34.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/source_index.rb
  35.    rubygems/version.rb:
  36.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/version.rb
  37.    rubygems/specification.rb:
  38.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/specification.rb
  39.    openssl.so:
  40.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/openssl.so
  41.      type: extension-library
  42.    openssl/bn.rb:
  43.      file: c:/ruby/lib/ruby/1.8/openssl/bn.rb
  44.    openssl/cipher.rb:
  45.      file: c:/ruby/lib/ruby/1.8/openssl/cipher.rb
  46.    openssl/digest.rb:
  47.      file: c:/ruby/lib/ruby/1.8/openssl/digest.rb
  48.    openssl/buffering.rb:
  49.      file: c:/ruby/lib/ruby/1.8/openssl/buffering.rb
  50.    fcntl.so:
  51.      file: c:/ruby/lib/ruby/1.8/i386-mswin32/fcntl.so
  52.      type: extension-library
  53.    openssl/ssl.rb:
  54.      file: c:/ruby/lib/ruby/1.8/openssl/ssl.rb
  55.    openssl/x509.rb:
  56.      file: c:/ruby/lib/ruby/1.8/openssl/x509.rb
  57.    openssl.rb:
  58.      file: c:/ruby/lib/ruby/1.8/openssl.rb
  59.    rubygems/gem_openssl.rb:
  60.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/gem_openssl.rb
  61.    rubygems/security.rb:
  62.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/security.rb
  63.    rubygems/custom_require.rb:
  64.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb
  65.    rubygems.rb:
  66.      file: c:/ruby/lib/ruby/site_ruby/1.8/rubygems.rb
  67.    ubygems.rb:
  68.      file: c:/ruby/lib/ruby/site_ruby/1.8/ubygems.rb
  69.    wxruby.so:
  70.      file: c:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt/wxruby.so
  71.      type: extension-library

该文件把hello_wx.rb所需的类库文件都包含进来了。

运行exerb hello_wx.exy,这时候生成的hello_wx.exe是可以执行的,问题是打开文件的同时会打开一个控制台窗口,要解决这个问题,就得修改hello_wx.exy文件,把cui改成gui。

  1. general:
  2.   startup: hello_wx.rb
  3.   core: gui #cui
  4.   kcode: none

再次运行exerb hello_wx.exy,生成一个红宝石图标的exe文件,OK!

另外,exy文件中还可以设置图标和版本信息。不再赘述。配置属性如下:

  1. resource:
  2. icon:
  3. - width : 16
  4. height: 16
  5. color : 4
  6. file : your_ico.ico
  7. - width : 32
  8. height: 32
  9. color : 4
  10. file : your_ico.ico
  11. version:
  12. file_version_number : 1.2.3.4
  13. product_version_number: 5.6.7.8
  14. comments : Comments Field
  15. company_name : Company Name Field
  16. legal_copyright : Legal Copyright Field
  17. legal_trademarks : Legal Trademarks Field
  18. file_version : File Version Field
  19. product_version : Product Version Field
  20. product_name : Product Name Field
  21. file_description : File Description Field
  22. internal_name : Internal Name Field
  23. original_filename : Original Filename Field
  24. private_build : Private Build Field
  25. special_build : Special Build Field