views:

317

answers:

2

Hi All,

Does anyone have any insights regarding compiling Ruby code for Windows? I've tried both "Ruby2Exe" and "OCRA", but both present their own issues. Ruby2Exe keeps presenting vague or confusing warnings such as "can't modify frozen string". OCRA on the other hand seems to want to run your script and assumes that there are no dynamic items.

For the record, my script accepts command line arguments as well as reading in and parsing a text file. OCRA doesn't like this aspect at all, and actually throws the warnings in my code as if I tried to run the script.

Anyway, if anyone has any quality means by which to compile ruby code for Windows, I'm all ears.

As a bit of an FYI, my goal with this particular script is to send email over SMTP. It is part of a larger non-ruby application, but the framework is incapable of sending email. I find Ruby enjoyable and rather easy to work with but don't wish to have every end user install Ruby -- hence, the need/desire to "compile" it.

I'm on a short time table and can't really afford to expend resources on writing this in C++, etc. However, if anyone has any insights on any existing Windows-compatible libaries/applications, do tell.

Much appreciated.

A: 

"OCRA on the other hand seems to want to run your script..."

The constant Ocra is defined at compile-time but not at run-time. So you can include logic based on whether or not the Ocra constant is defined. For example:

   app = MyApp.new
   if not defined?(Ocra)
     app.main_loop
   end
David Mullet
Please forgive me, but it seems you're starting in the middle of a thought here. I've not looked at the OCRA code. I simply used it to compile. Would you mind expanding on that statement?
humble_coder
Sorry for the confusion. Ocra must load your script in order to determine what files (including required gems) to include in the executable. I am assuming that one of your questions is regarding how to avoid having Ocra execute your entire script. To quote the developer of Ocra, "You can detect whether Ocra is currently building your script by looking for the 'Ocra' constant. If it is defined, Ocra is currenly building the executable from your script. For example, you can use this to avoid opening a GUI window when compiling executables."
David Mullet
Ok, still confused, but less so. So do I place that code in the OCRA file or in my ".rb" file?
humble_coder
You would add something like this to your ruby script (".rb file"). If you prefer, feel free to send me your code (or a genericized version) via email (firstname dot lastname at gmail dot com) and I can offer specific suggestions.
David Mullet
Much appreciated. Sent. I look forward to your input.
humble_coder
A: 

I have this same question about ocra. I try to use ocra to compile my ruby script and it starts to run it. I'm not using any gems in my script, but I do require console input. Is it okay if I email you my script, or would you prefer explaining how to modify my ruby script to make this work?

Chris
Also, sorry this is not actually a question, but I didn't see a spot to ask this without creating another question.
Chris
I don't currently have java installed, but I am considering using the jruby path. I've never used jruby though, and it's been a while since I used java. I'd like it if I could just get the ocra to work.
Chris