Distributing Ruby program as a standalone executable (exe) for windows

Hello there,

I’m a newbie. I have written a ruby program on my mac which uses
NET::HTTP. There’s no GUI, its all working via terminal input from the
user. My program however needs to be invoked and run from a windows
machine.

Is there a way to make my little program a standalone executable so that
my user can double click the exe and run it as per normal from their
windows machine? I would prefer to avoid installing ruby on the windows
machine (if I can).

Is this possible, and if it is how do I go about it?

Thank-you in advance, Michelle

Hello,

I use OCRA under windows : “the One-Click Ruby Application Builder”
http://ocra.rubyforge.org/

It’s OK if your application don’t use resources (dll, gtk…) not
packaged with a gem.

It is possible, using “Ocra” gem. (There are also some other ways, but
this one is the simplest.)

Just gem install ocra, then run ocra yourscript.rb. The script
will now be executed once, then Ocra will collect all the dependencies
and pack them in a single exe, along with the script. (You probably
need to do this on a Windows computer wih Ruby installed.) A
yourscript.exe file will be generated, you should be able to run it on
any Windows machine.

Internally, this .exe file will unpack Ruby interpreter, libraries and
the script to a temporary directory, run it, then clean up after
itself.

If your script requires or reads anything from the directory you run
it in, you’ll probably also need to add these two lines to the top of
it to make it work with Ocra:

$:.unshift File.dirname($0)
Dir.chdir File.dirname($0)

You can read further docs on RubyGems.org.

2011/8/11 Michelle P. [email protected]:

Perfect, thanks very much Bartosz and Regis.

I’ll install and run the gem on osx first (where my code resides). And
see what happens when I run the exe on windows. If I run into any
troubles I’ll post about it here.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 15.08.2011 07:55, schrieb Michelle P.:

Perfect, thanks very much Bartosz and Regis.

I’ll install and run the gem on osx first (where my code resides).
And see what happens when I run the exe on windows. If I run into any
troubles I’ll post about it here.

As far as I know OCRA doesn’t work on any other platform than Windows.
You have to package your code on your Windows platform.

Vale,
Marvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJOSMrfAAoJELh1XLHFkqhaQUsH/jKkxnGZGruBwBvnWxYMU/T0
OEv+EDIeVEOam6j1jMld/OYeAveUQ1Oh4OCWuKyh9I7zxszkB0MCjgS7NhbNL+xO
CfF07ztpUS/pQYnfxObhQhRS+q+v1NRBJ+0wx7K2bO+vjHCvdq5lfiFNwy4hiyGE
Ka4LWdM5M9dRynaKgGk0qw+HeZzjg+WvjOHMP35Ipk5TKF7uOHkYy9GuvrnpjQO9
UyIB4Hc4Mh4kX3UwBjX9rCMEY7QNC3/gEtQTHFm02/SOFTA758fv3Qf4nueXF+N0
2AKnfF+wWphaSdSLkvVpEkI/AY7pDVg4j6FxoqI+i0QfgJsUbI928LOm27SfXt0=
=g2+X
-----END PGP SIGNATURE-----

Ocra is the key. I have used it with great success doing exactly what
you wish to do.

Jeff

Hello there,

I tried to use ocra myscript.rb under Windows XP

require ‘watir’
printf “Hello World”
ie = Watir::IE.start “www.google.com

Ocra create the exe file but I get this Warning and i can’t run my exe
file:

WARNING: Watir::Safari was not loadable

Note : am not using Safari in my script. and my ocra version is Ocra
1.3.0 and ruby 1.9.2 Please let me know how can i fix this problem or if
there is other way to distribute my script

Why it does not work on Linux?

Is there a way to make my little program a standalone executable so that
my user can double click the exe and run it as per normal from their
windows machine? I would prefer to avoid installing ruby on the windows
machine (if I can).

may be helpful to you.

Am working in Windows XP.