Creating ruby script exe

Hi All,

I have been using the gem 'ocra' to create .exe files for my ruby
scripts. I run the following command:

ocra --console foo.rb

This creates the .exe but also runs the script once to create the .exe.
I am facing an issue where i have a script which uses 'file-tail' to
tail a log file. In this case when i run the above 'ocra' command, it
does not create the .exe as the script runs and starts to watch the log
file as it would normally do and hence ocra .exe creation does not
complete.

Any thoughts how to avoid the above?
Thanks

···

--
Posted via http://www.ruby-forum.com/.

Looks like there's an example in the docs:

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:

   app = MyApp.new
   if not defined?(Ocra)
     app.main_loop
   end

···

On Tue, Jun 18, 2013 at 5:27 AM, Rochit Sen <lists@ruby-forum.com> wrote:

Hi All,

I have been using the gem 'ocra' to create .exe files for my ruby
scripts. I run the following command:

ocra --console foo.rb

This creates the .exe but also runs the script once to create the .exe.
I am facing an issue where i have a script which uses 'file-tail' to
tail a log file. In this case when i run the above 'ocra' command, it
does not create the .exe as the script runs and starts to watch the log
file as it would normally do and hence ocra .exe creation does not
complete.

Any thoughts how to avoid the above?
Thanks

--
Posted via http://www.ruby-forum.com/\.

I was not sure where to post this I have worked on this several days.
I posted the entire log from gnu radio and ./multimode.py in attached
txt
I think that 4.6.3 is not compatible or library mismatch "its a clean
install gnuradio-companion is working but ./multimode gives me this and
other errors
Im sorry if I posted this in the wrong place very new to Linux and
gnuradio

self.gr_multiply_const_vxx_2 = gr.multiply_const_vff((1.0 if
mh.get_mode_type(mode) == "FM" else 0.0))
  File
"/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gnuradio_core_gengen.py",
line 9713, in multiply_const_vff

Bryan

Attachments:
http://www.ruby-forum.com/attachment/8524/Untitled_Document_1

···

--
Posted via http://www.ruby-forum.com/.

Ocra scans your script before it executes it anyway, but you might find
you'll need to actively use some gems for them to picked up properly.

Here's an excerpt from a class I use with Ocra builds sometimes:

···

________

def initialize

  # Allow EXE build without running.
  if defined?(Ocra)
    # Let OCRA pick up the cookies from Mechanize.
    Mechanize.new.cookies
    # Quit so Ocra can do its thing.
    exit
  end

  # Normal stuff goes here...
  @agent = Mechanize.new

end

--
Posted via http://www.ruby-forum.com/.

That's probably because you're using an old version of Ruby: version
1.9.2.

I noticed this message on a related error when googling the problem:
"NOTE: Gem::Specification#installation_path is deprecated, use base_dir.
It will be removed on or after 2011-10-01."

You should probably install Ruby 1.9.3 or 2.0 and make sure you're using
the latest version of Ocra.

If you can't upgrade your Ruby version for some reason, you'll probably
have to downgrade Ocra until you find a compatible version. Although
that'll undo all the bugfixes since that version was released...

FYI, --console is the default when building an ".rb" file. You don't
need to specify that.

···

--
Posted via http://www.ruby-forum.com/.

You could install them from the old gems (I think they're in the cache
folder near the extracted gem folders), but it would be best to just
install the ones you need, thereby ensuring that you have the latest
versions.

Anyway, it's easy to install them together:
gem install this_gem this_gem_too and_this_gem

···

--
Posted via http://www.ruby-forum.com/.

That's a side-effect of using the command --no-dep-run

Here's the code sample I suggested before, with an extra note:

def initialize

  # Allow EXE build without running.
  if defined?(Ocra)
    # Let OCRA pick up the cookies from Mechanize.
    Mechanize.new.cookies
    # Let OCRA pick up file-tail
    ... something that uses file-tail here...
    # Quit so Ocra can do its thing.
    exit
  end

  # Normal stuff goes here...
  @agent = Mechanize.new

end

···

--
Posted via http://www.ruby-forum.com/.

Devin Christensen wrote in post #1112819:

Looks like there's an example in the docs:

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:

   app = MyApp.new
   if not defined?(Ocra)
     app.main_loop
   end

Hi David,
I will write the above at the beginning of my script? after the require
statements? or at the end?

Thanks

···

--
Posted via http://www.ruby-forum.com/\.

Joel Pearson wrote in post #1112855:

Ocra scans your script before it executes it anyway, but you might find
you'll need to actively use some gems for them to picked up properly.

Here's an excerpt from a class I use with Ocra builds sometimes:

________

def initialize

  # Allow EXE build without running.
  if defined?(Ocra)
    # Let OCRA pick up the cookies from Mechanize.
    Mechanize.new.cookies
    # Quit so Ocra can do its thing.
    exit
  end

  # Normal stuff goes here...
  @agent = Mechanize.new

end

Hi Joel,All

I found a option for ocra:
--no-dep-run using this ocra does not run my script and created .exe.
This part is resolved.
Now my script has some require statements as well for gems. So i created
a bundler file using:
bundle init
Then added the following in my Gemfile:
source "https://rubygems.org"
gem "file-tail"
gem "pony"

I then ran the: bundle install which created a Gemfile.lock

Then finally i ran the following ocra command:
C:code>ocra --console --gemfile Gemfile --no-dep-run tailtest.rb

Upon running it scans the Gemfile and then gives me error as below:

···

---
=== Scanning Gemfile
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:1879:in
`method_mi
ssing': undefined method `installation_path' for
#<Gem::Specification:0x97b0e4 t
ins-0.8.2> (NoMethodError)
        from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:557:in `blo
ck in find_gem_files'
        from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:556:in `fin
d_gem_files'
        from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:701:in `bui
ld_exe'
        from
C:/Ruby192/lib/ruby/gems/1.9.1/gems/ocra-1.3.0/bin/ocra:1138:in `bl
ock in <top (required)>'
---
My script has the following statements in the beginning:

require 'rubygems'
require 'bundler/setup'
Bundler.require

Thanks in advance!

--
Posted via http://www.ruby-forum.com/\.

Joel Pearson wrote in post #1113153:

That's probably because you're using an old version of Ruby: version
1.9.2.

I noticed this message on a related error when googling the problem:
"NOTE: Gem::Specification#installation_path is deprecated, use base_dir.
It will be removed on or after 2011-10-01."

You should probably install Ruby 1.9.3 or 2.0 and make sure you're using
the latest version of Ocra.

If you can't upgrade your Ruby version for some reason, you'll probably
have to downgrade Ocra until you find a compatible version. Although
that'll undo all the bugfixes since that version was released...

FYI, --console is the default when building an ".rb" file. You don't
need to specify that.

Thanks for the info Joel.
I upgraded ruby to 1.9.3p429. But now my gems dont work as they are in
the /lib folder of old ruby installation. Could I import those with a
command or i would need to re-install all of those gems again?

···

--
Posted via http://www.ruby-forum.com/\.

Joel Pearson wrote in post #1113211:

You could install them from the old gems (I think they're in the cache
folder near the extracted gem folders), but it would be best to just
install the ones you need, thereby ensuring that you have the latest
versions.

Anyway, it's easy to install them together:
gem install this_gem this_gem_too and_this_gem

Hi Joel.
Thanks for your help. Issue resolved.

Cheers

···

--
Posted via http://www.ruby-forum.com/\.

Joel Pearson wrote in post #1113564:

That's a side-effect of using the command --no-dep-run

Here's the code sample I suggested before, with an extra note:

def initialize

  # Allow EXE build without running.
  if defined?(Ocra)
    # Let OCRA pick up the cookies from Mechanize.
    Mechanize.new.cookies
    # Let OCRA pick up file-tail
    ... something that uses file-tail here...
    # Quit so Ocra can do its thing.
    exit
  end

  # Normal stuff goes here...
  @agent = Mechanize.new

end

Hi Joel,
Thanks. your suggestion worked. But when i run the exe i am getting
error:
"uninitialized constant yaml" and the exe exits.
I am using the YAML.load_file method in my script to read from a yaml
file

Any thoughts?

···

--
Posted via http://www.ruby-forum.com/\.

Rochit Sen wrote in post #1113269:

Joel Pearson wrote in post #1113211:

You could install them from the old gems (I think they're in the cache
folder near the extracted gem folders), but it would be best to just
install the ones you need, thereby ensuring that you have the latest
versions.

Anyway, it's easy to install them together:
gem install this_gem this_gem_too and_this_gem

Hi Joel.
Thanks for your help. Issue resolved.

Cheers

Hi Joel,

Its seems there is till some issue. I had created an exe using the
following command:

ocra --gemfile Gemfile --no-dep-run script.rb

This creates a script.exe file, also while creating script i successful
messaging that the gems are being read from the Gemfile. When in run the
exe, i get a error in loading one of the gems. In this case its
file-tail gem. I have attached a screenshot of the error.
What could be the issue?

Attachments:
http://www.ruby-forum.com/attachment/8538/gem_error.jpg

···

--
Posted via http://www.ruby-forum.com/\.

That would rather be

   NameError: uninitialized constant YAML

You probably forgot to require 'yaml'.

Regards,
Marcus

···

Am 26.06.2013 19:04, schrieb Rochit Sen:

Joel Pearson wrote in post #1113564:

That's a side-effect of using the command --no-dep-run

Here's the code sample I suggested before, with an extra note:

def initialize

   # Allow EXE build without running.
   if defined?(Ocra)
     # Let OCRA pick up the cookies from Mechanize.
     Mechanize.new.cookies
     # Let OCRA pick up file-tail
     ... something that uses file-tail here...
     # Quit so Ocra can do its thing.
     exit
   end

   # Normal stuff goes here...
   @agent = Mechanize.new

end

Hi Joel,
Thanks. your suggestion worked. But when i run the exe i am getting
error:
"uninitialized constant yaml" and the exe exits.
I am using the YAML.load_file method in my script to read from a yaml
file

--
<https://github.com/stomar/&gt;

Rochit Sen wrote in post #1113647:

Joel Pearson wrote in post #1113564:

That's a side-effect of using the command --no-dep-run

Here's the code sample I suggested before, with an extra note:

def initialize

  # Allow EXE build without running.
  if defined?(Ocra)
    # Let OCRA pick up the cookies from Mechanize.
    Mechanize.new.cookies
    # Let OCRA pick up file-tail
    ... something that uses file-tail here...
    # Quit so Ocra can do its thing.
    exit
  end

  # Normal stuff goes here...
  @agent = Mechanize.new

end

Hi Joel,
Thanks. your suggestion worked. But when i run the exe i am getting
error:
"uninitialized constant yaml" and the exe exits.
I am using the YAML.load_file method in my script to read from a yaml
file

Any thoughts?

Hi Joel,
Please ignore my previous email. Issue is resolved :slight_smile:

Thanks for your help.

···

--
Posted via http://www.ruby-forum.com/\.

For future posts: good netiquette would be to also post
the solution in your "never mind, I figured it out" email.

Regards,
Marcus

···

Am 26.06.2013 19:35, schrieb Rochit Sen:

Please ignore my previous email. Issue is resolved :slight_smile:

Thanks for your help.

--
<https://github.com/stomar/&gt;

unknown wrote in post #1113652:

···

Am 26.06.2013 19:35, schrieb Rochit Sen:

Please ignore my previous email. Issue is resolved :slight_smile:

Thanks for your help.

For future posts: good netiquette would be to also post
the solution in your "never mind, I figured it out" email.

Regards,
Marcus

Agreed.. just being lazy @ midnight

--
Posted via http://www.ruby-forum.com/\.