Ruby脚本转换成可执行文件---OCRA

Ruby脚本转换成可执行文件

 

今天无意中看到了一篇关于OCRA工具的介绍,体验了一下,不错的一个工具,

可以很轻松的将ruby脚本转换成exe文件

 

当然需要安装ocra的gem包, gem install ocra 即可

 

ocra命令参数

 

ocra --help
ocra [options] script.rb
options可取值如下:
--dll dllname    Include additional DLLs from the Ruby bindir.
--no-lzma        Disable LZMA compression of the executable.
--quiet          Suppress output.
--help           Display this information.
--windows        Force Windows application (rubyw.exe)
--console        Force console application (ruby.exe)
--no-autoload    Don't load/include script.rb's autoloads
--icon      Replace icon with a custom one
--version        Display version number

 

 

以下是测试过程:

 

先创建了一个测试脚本test.rb

 

require 'pathname'
require_relative 'hello'

path = Pathname.new(File.dirname(__FILE__)).realpath
f = File.open("F:\\test.txt","w+")
f.puts "test"
f.puts path
f.close
hello "hello world"

 

 

为了测试能否将依赖的脚本一并打包,该脚本引用了hello.rb

 

 

def hello s
 puts s
end

 

 

在命令行中执行 

 

F:\>ocra --console test.rb

=== Loading script to check dependencies

hello world

=== Including 53 encoding support files (3194880 bytes,

 

DL is deprecated, please use Fiddle

=== Building test.exe

=== Adding user-supplied source files

=== Adding ruby executable ruby.exe

=== Adding detected DLL C:/ruby-2.0.0/bin/zlib1.dll

=== Adding detected DLL C:/ruby-2.0.0/bin/LIBEAY32.dll

=== Adding detected DLL C:/ruby-2.0.0/bin/SSLEAY32.dll

=== Adding detected DLL C:/ruby-2.0.0/bin/libffi-6.dll

=== Adding library files

=== Compressing 9578823 bytes

=== Finished building test.exe (2410533 bytes)

 

结果:

文件操作正常,打印正常

不过使用path来获取脚本路径,这个会返回一个临时目录

C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ocr18A.tmp/src

所以这个方法应该用不了

 

path = Pathname.new(File.dirname(__FILE__)).realpath

 

其他的用法还有待体验。

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值