# Use Ruby to create Win executable?

**URL:** <https://rubytalk.org/t/use-ruby-to-create-win-executable/54845>\
**Category:** ruby-talk\
**Created:** [11 August 2009 09:27 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845 "2009-08-11T09:27:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manuel\_Souto\_Pico](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@Manuel\_Souto\_Pico](https://rubytalk.org/u/Manuel_Souto_Pico)\
**Post date:** [11 August 2009 09:27 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/1 "2009-08-11T09:27:25Z")

</div>

Hi,

I would like to post a general question about the convenience of using  
Ruby to program a simple application consisting of an interface where  
the user inputs some options and that interacts with another program's  
API to create some files.

I'll be doing this in Windows, by the way. I have Cygwin too.

I was suggested using VBScript to create a HTA application, because it's  
easy to program and easy to run, but I wanted to give Ruby a chance  
first. Java would be okay too but it take me much longer to learn.

So here are my questions (1 and 2 are the important ones):

1. I think it's entirely possible to create a GUI with Ruby (either with  
Ruby itself or with Shoes). Is this right? (I'm more familiar with  
writing Perl scripts that I execute on the command-line, I have no  
experience with writing GUI).

2. I think it's possible to convert the final program to a executable  
file that I can distribute to Windows users for them to run the program  
without the need to install Ruby first. Is this right? How should I do  
that? How well does it work?

3. A subjective, optional question, for whoever feels like answering and  
thinks they're not too biased. How do you think Ruby compares to  
VBScript in terms of both difficulty to learn from scratch and  
usefulness once you learnt? I only know some perl and php.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Manuel\_Souto\_Pico](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@Manuel\_Souto\_Pico](https://rubytalk.org/u/Manuel_Souto_Pico)\
**Post date:** [11 August 2009 09:27 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/2 "2009-08-11T09:27:52Z")

</div>

Sorry, I forgot to say goodbye and to thank you in advance for any  
hints.

Cheers, Manuel

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![James\_Britt3](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@James\_Britt3](https://rubytalk.org/u/James_Britt3)\
**Post date:** [11 August 2009 22:58 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/3 "2009-08-11T22:58:05Z")

</div>

Manuel Souto pico wrote:

> Hi,
> 
> I would like to post a general question about the convenience of using  
> Ruby to program a simple application consisting of an interface where  
> the user inputs some options and that interacts with another program's  
> API to create some files.
> 
> I'll be doing this in Windows, by the way. I have Cygwin too.
> 
> I was suggested using VBScript to create a HTA application, because it's  
> easy to program and easy to run, but I wanted to give Ruby a chance  
> first. Java would be okay too but it take me much longer to learn.

Use JRuby + Monkeybars for effortless GUI building, then use Rawr to create the exe file.

> So here are my questions (1 and 2 are the important ones):
> 
> 1. I think it's entirely possible to create a GUI with Ruby (either with  
> Ruby itself or with Shoes). Is this right? (I'm more familiar with  
> writing Perl scripts that I execute on the command-line, I have no  
> experience with writing GUI).

For anything serious, look at using Swing + JRuby.

> 2. I think it's possible to convert the final program to a executable  
> file that I can distribute to Windows users for them to run the program  
> without the need to install Ruby first. Is this right? How should I do  
> that? How well does it work?

Rawr bundles up everything needed to run the app. The end user just needs to have Java (almost guaranteed).

> 3. A subjective, optional question, for whoever feels like answering and  
> thinks they're not too biased. How do you think Ruby compares to  
> VBScript in terms of both difficulty to learn from scratch and  
> usefulness once you learnt? I only know some perl and php.

VBScript is OK for short hacks and scripting Office apps. Not for anything substantial.

> **···**
>
> --  
> James Britt
> 
> [www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys  
> [www.ruby-doc.org](http://www.ruby-doc.org) - Ruby Help & Documentation  
> [www.rubystuff.com](http://www.rubystuff.com) - The Ruby Store for Ruby Stuff  
> [www.neurogami.com](http://www.neurogami.com) - Smart application development

---

<div class="post-metadata">

**Author:** ![Richard\_Conroy1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Richard\_Conroy1](https://rubytalk.org/u/Richard_Conroy1)\
**Post date:** [12 August 2009 18:42 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/4 "2009-08-12T18:42:31Z")

</div>

> I was suggested using VBScript to create a HTA application, because it's  
> easy to program and easy to run, but I wanted to give Ruby a chance  
> first. Java would be okay too but it take me much longer to learn.

Ruby would be more interesting too ... 😜

> 1. I think it's entirely possible to create a GUI with Ruby (either with  
> Ruby itself or with Shoes). Is this right? (I'm more familiar with  
> writing Perl scripts that I execute on the command-line, I have no  
> experience with writing GUI).

If you have no UI experience, Shoes is awesome. Simple and to the point.  
All of the other Ruby native UI options do have a non-trivial learning  
curve.

> 2. I think it's possible to convert the final program to a executable  
> file that I can distribute to Windows users for them to run the program  
> without the need to install Ruby first. Is this right? How should I do  
> that? How well does it work?

The options are limited - via JRuby you cab use Rawr to achieve this. There  
is  
also the RubyScript2exe option, but I am not sure how maintained this is.

Also, shoes itself provides a windows (and Mac) packaging solution that  
works as you describe (downloading necessary binaries on demand).

> 3. A subjective, optional question, for whoever feels like answering and  
> thinks they're not too biased. How do you think Ruby compares to  
> VBScript in terms of both difficulty to learn from scratch and  
> usefulness once you learnt? I only know some perl and php.

You are not going to get much subjectivity here from me .... 😜

Ruby is simply far more versatile than the other options (PHP, VBScript,  
can't comment on perl). You learn it for shell scripting purposes, testing,  
building software etc. and then  
somehow your knowledge is applicable in entirely different domains.

Its a much more interesting leaning experience. The initial learning curve  
is not steep,  
but it is a huge curve, and you are productive at a very early part of it.

regards,  
Richard

---

<div class="post-metadata">

**Author:** ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)\
**Post date:** [11 August 2009 10:32 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/5 "2009-08-11T10:32:40Z")

</div>

Hi Manuel,

Manuel Souto Pico wrote:

> 1. I think it's entirely possible to create a GUI with Ruby (either with  
> Ruby itself or with Shoes). Is this right? (I'm more familiar with  
> writing Perl scripts that I execute on the command-line, I have no  
> experience with writing GUI).

Ruby itself does not provide a GUI, but there are serveral different GUI  
toolkits for Ruby out there, Shoes is only one of them. If you have the  
Tk sources installed on your computer (I think you can get them from the  
TCL/Tk website for Windows) you should be able to use the "tk" library  
of Ruby's standard library. You could also use FxRuby or wxRuby (my  
favourite) or QtRuby, only to name a few. The most are available through  
RubyGems (type gem --version on the command line to see if it was  
installed with Ruby [what is the regular case with Ruby 1.9.x] )

Manuel Souto Pico wrote:

> 2. I think it's possible to convert the final program to a executable  
> file that I can distribute to Windows users for them to run the program  
> without the need to install Ruby first. Is this right? How should I do  
> that? How well does it work?

For this goes the same as for 1. - there are serveral solutions to that.  
For long times rubyscript2exe.rb was \*the\* Windows executable generator  
(it wasn't a compiler), but nowadays you should use the Gem ocra  
(One-Click Ruby Application Builder) which does also care about the Gems  
needed for your scripts and is currently maintained.

Marvin

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Manuel\_Souto\_Pico](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@Manuel\_Souto\_Pico](https://rubytalk.org/u/Manuel_Souto_Pico)\
**Post date:** [12 August 2009 19:44 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/6 "2009-08-12T19:44:41Z")

</div>

Hello,

Due to limited time (it had to be done by tomorrow, when I go on  
holidays) I'm developing the first part of the program as a web  
application with PHP and Javascript (with which I'm more familiar), and  
that'll do the trick for now. Later on, I want to keep exploring Ruby  
and if possible migrate and expand this application.

I'm very interested in Ruby and I am very happy with the response from  
other users like you in this forum. I just wanted to say that and thank  
you for your help so far. Hopefully I'll get to something when I come  
back from my holidays in a few days. So don't think that I asked and  
then disappeared 😉

Cheers, and happy August.

Manuel

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Marc\_Heiler](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Marc\_Heiler](https://rubytalk.org/u/Marc_Heiler)\
**Post date:** [11 August 2009 11:34 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/7 "2009-08-11T11:34:28Z")

</div>

> 1. I think it's entirely possible to create a GUI with Ruby (either with  
> Ruby itself or with Shoes). Is this right? (I'm more familiar with  
> writing Perl scripts that I execute on the command-line, I have no  
> experience with writing GUI).

There are plenty of GUI bindings for ruby towards i.e. ruby-gtk, qt,  
FOX, wxwidgets and so on. Ruby is pretty much in the same boat as perl  
is here.

I think you might also invoke some basic window GUI components like an  
alertbox and similar via ruby only. But I think a nice toolkit would be  
a better choice in the long run.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Manuel\_Souto\_Pico](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@Manuel\_Souto\_Pico](https://rubytalk.org/u/Manuel_Souto_Pico)\
**Post date:** [11 August 2009 13:54 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/8 "2009-08-11T13:54:24Z")

</div>

Hi Marvin,

> you should use the Gem ocra  
> (One-Click Ruby Application Builder) which does also care about the Gems  
> needed for your scripts and is currently maintained.

I want to focus on this part for now. I've tried to install and run ocra  
with a simple ruby file, but something didn't work. Let me open a new  
post for that, and once I've sorted that out I'll come back here and  
comment more.

Thanks to the both of you for your replies!  
Manuel

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![paron1](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@paron1](https://rubytalk.org/u/paron1)\
**Post date:** [13 August 2009 12:05 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/9 "2009-08-13T12:05:06Z")

</div>

Even if I were in a big hurry, I'd give Titanium a look, too.  
[http://www.appcelerator.com/products/titanium-desktop/](http://www.appcelerator.com/products/titanium-desktop/)

> **···**
>
> On Aug 12, 3:44 pm, Manuel Souto Pico \<m.soutop...@gmail.com\> wrote:
> 
> > Hello,
> > 
> > Due to limited time (it had to be done by tomorrow, when I go on  
> > holidays) I'm developing the first part of the program as a web  
> > application with PHP and Javascript (with which I'm more familiar), and  
> > that'll do the trick for now. Later on, I want to keep exploring Ruby  
> > and if possible migrate and expand this application.
> > 
> > I'm very interested in Ruby and I am very happy with the response from  
> > other users like you in this forum. I just wanted to say that and thank  
> > you for your help so far. Hopefully I'll get to something when I come  
> > back from my holidays in a few days. So don't think that I asked and  
> > then disappeared 😉
> > 
> > Cheers, and happy August.
> > 
> > Manuel
> > 
> > --  
> > Posted viahttp://www.ruby-forum.com/.

---

<div class="post-metadata">

**Author:** ![Marvin\_GA\_lker](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@Marvin\_GA\_lker](https://rubytalk.org/u/Marvin_GA_lker)\
**Post date:** [11 August 2009 13:55 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/10 "2009-08-11T13:55:06Z")

</div>

Marc Heiler wrote:

> I think you might also invoke some basic window GUI components like an  
> alertbox and similar via ruby only.

Yes, on Windows you can use features like the MessageBox() function from  
the Windows API. There are bindings to the Windows API in Ruby's  
standard library, but they have been deprecated in Ruby 1.9, so I would  
recommend you to use a gem here, too. win32-api does a very good job:

&nbsp;&nbsp;require "rubygems" #if you're running pre-1.9  
&nbsp;&nbsp;require "win32/api"

&nbsp;&nbsp;#Values just out of my head, I have no Windows to try at the moment  
&nbsp;&nbsp;#see MSDN (or Google 😉 ) for the correct values  
&nbsp;&nbsp;MB\_OKCANCEL = 1  
&nbsp;&nbsp;MB\_ICONERROR = 16  
&nbsp;&nbsp;ID\_OK = 1  
&nbsp;&nbsp;ID\_CANCEL = 2

&nbsp;&nbsp;#Retrieve function "MessageBox" from "user32.dll"  
&nbsp;&nbsp;msgbox = Win32::API.new("MessageBox", 'LPPI', 'I', "user32")  
&nbsp;&nbsp;#This should display a dialog box with a white-on-red X and two  
buttons  
&nbsp;&nbsp;ret = msgbox.call(0, "An error occured. Do you want to continue?",  
"Error", MB\_ICONERROR | MB\_OKCANCEL) #The 0 indicates there's no parent  
window  
&nbsp;&nbsp;if ret == ID\_OK  
&nbsp;&nbsp;&nbsp;&nbsp;#Continue your operation...  
&nbsp;&nbsp;elsif ret == ID\_CANCEL  
&nbsp;&nbsp;&nbsp;&nbsp;#Cancel your operation...  
&nbsp;&nbsp;end

Marvin

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Manuel\_Souto\_Pico](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@Manuel\_Souto\_Pico](https://rubytalk.org/u/Manuel_Souto_Pico)\
**Post date:** [11 August 2009 14:16 UTC](https://rubytalk.org/t/use-ruby-to-create-win-executable/54845/11 "2009-08-11T14:16:15Z")

</div>

Manuel Souto Pico wrote:

> I've tried to install and run ocra  
> with a simple ruby file, but something didn't work. Let me open a new  
> post for that, and once I've sorted that out I'll come back here and  
> comment more.

In case you think you can help, this is the related post:

> **[Fail to load the win32-api gem when running OCRA](https://www.ruby-forum.com/t/fail-to-load-the-win32-api-gem-when-running-ocra/173572)**
>
> Hi, I’m trying to run ocra but I seem to have a problem with win32-api. I’m running this on cygwin and have also tried in an Ubuntu server. Running ocra outputs an error that tells me to install win32-api, which I do, but after that I still...

Thanks!  
Manuel

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
