Sunday, September 28, 2008

rubyscript2exe.rb and 623 Can't modify frozen string (Type Error)

rubyscript2exe.rb and Frozen String error

A tiny bug

Today I bumped into this error in rubyscript2exe.rb:

rubyscript2exe.rb:623:in `replace': can't modify frozen string (TypeError)

I'm using ruby 1.8.6 (2008-08-08 patchlevel 286) [i686-linux] and rubyscript2exe.rb version 0.5.3 (29.05.2007) which is the latest to this date. However the forementioned error occurs when trying to run rubyscript2exe.rb.

Ungoogled

I quickly googled for an answer but was out of luck, so I just jumped in and found the line, just rephrased the line and here is the change, just edit the rubyscript2exe.rb file at line 623, it looks like this:


$0.replace(File.expand_path("./init.rb"))


  $_0 = File.expand_path("./init.rb")
  alias $__0 $0
  alias $0 $_0

This was fixed from a simple '=' assignment I had proposed to the above solution, based on a comment from cowlibob (thanks), he has the modified version up in github, and you can Get it at http://github.com/cowlibob/rubyscript2exe.

Bye!

Hope this works for you, good luck.

Gabriel Medina.

16 comments:

Anonymous said...

Hi, I found your blog entry about the problem with "can't modify frozen string" but your solution did not seem to work for me, indeed it didn't even seem to apply on my linux box.

For a start, the rubyscript2exe that gets installed on my linux box seems to be a thin wrapper around something called 'realstuff.rb'

Now, 'realstuff.rb' does have the line you mention in it but changing it as you described didn't make any difference and I still got that error

The rubyscript2exe.rb file itself only has a few lines in it, and I noticed that the 4th line seemed similar to your suggested original change (see below) so I changed that line to read
$0 = realstuff if isapplication
and I no longer get the error. Unfortunately it doesn't produce an executable either.

I'm hoping you might have some insight into this issue.

Many thanks,
David Jameson

Rha7DotCom said...

Could you give a little more info on your Linux (ubuntu, centos, fedora) and rubyscript2exe version (0.5.3???) and method of installation (rpm, deb, apt-get,
yum, up2date?)

This post applies to rubyscript2exe.rb file from
http://www.erikveen.dds.nl/rubyscript2exe
Section 6. Download.

I suggest you uninstall your current rubyscript2exe.rb and download the one mentioned above, move it to /usr/local/bin/, chmod +x it, and just make the change in place.

Hope this helps.

David Jameson said...

Actually, I have tried it on both ubuntu desktop and on Fedora 9 with exactly the same results.

I have tried using gem, apt-get, yum as well as downloading directly through http://www.erikveen.dds.nl/rubyscript2exe/download/rubyscript2exe.rb

In the last, for what it's worth, the line you suggest changing is line number 621, not 623 as in your blog. Changing that line does eliminate the error message but, for example, when I now try

ruby rubyscript2exe.rb foo.rb

I get no errors, but no foo is produced either. (foo.rb is a single line helloworld type program)

Viper said...

I found this thread through google and I had the same error message. I was using 186-26 with the Windows One-Click installer. My friend even got the same error using 1.9.1 RC2

My solution was two things. One was to make sure I had the latest rubyscript2exe

gem install rubyscript2exe

This gave me version 0.5.3 of rubyscript2exe


But the key for me the was updating to 1.8.7 stable release of Ruby. After that everything worked.

I hope 1.9.1 final has the same joy 1.8.7 gave me.

-Roderick

Baron5X said...

I'm going into my second week of working on this script and no matter what i do, i just can't seem to get it to work. I'm running on Kubuntu and using Ruby 1.8.7-p72 with the latest rubyscript2exe (0.5.3). Doing all these changes, I ge the same problem where I run it, it works (no errors) but my .exe is nowhere to be found.

Scwewywabbit said...

I'm having the same problems... running Ubuntu, Ruby 1.8.6, and rubyscript2exe 0.5.3 and I got the frozen string problem.

Edited it, and no errors, but it seems like the script isn't doing anything.

I have the same setup in Vista, and it works fine...

Scwewywabbit said...

Here's somewhat of a "fix", after hours of staring at my screen.

When you run rubyscript2exe, run it with a parameter such as: "--rubyscript2exe-verbose"

Here's how you would convert a file called test.rb:

ruby rubyscript2exe.rb test.rb --rubyscript2exe-verbose

my problem is that it messes up if I include "rubygems" (there's always a catch, right?) - I get this error:

`require': no such file to load -- rubygems (LoadError)


I don't know... at least it works as a non-solution for now!

cowlibob said...

I've noticed that $0 is not re-allocated when $0 = File.expand_path('./init.rb') is used. This can leave the string truncated, hence the rest of the task fails silently, as some of your commenter's have noticed. See http://github.com/cowlibob/rubyscript2exe for another way, using alias

Rha7DotCom said...

Thanks Cowlibob. I updated the post according to your fix, and linked to it.

Thanks for reading.

Gabriel.

Fri3ng3R said...

Thankz..Nice Work...

Shawn Lindsey said...

Thank you for your post. It helped get me on the correct path. It still took me 4-5 hours to get a solution though.

I would like to post my solution to possibly help others who have landed here.

The problem seems to be that the code for the gem rubyscript2exe does not work for my installation of Ruby (which is a very common one) I use Ruby 1.8.6-287.

My OS is Windows XP

The solution for me... step by step.

1. Go here and download this version of rubyscript2exe >> http://github.com/cowlibob/rubyscript2exe/tree/master

Save it anywhere you want.. and unzip it there.

2. Right Click COPY the file rubyscript2exe.rb

3. Now navigate to the directory where your ruby file that you want to turn into a .exe is.

4. PASTE rubyscript2exe.rb right there next to the file you want to make a .exe

5. from a command window type Ruby rubyscript2exe.rb yourfile.rb

replace yourfile.rb with the name of the rubyfile you wrote.

This worked for me. It was a fairly complex program as well.. A GUI built with FXRUBY.

Shawn Lindsey
http://ShawnLindsey.com

Anonymous said...

I have the same scenario as Shawn above, and the change in the original post worked for me. Thanks!

Андрей said...

Thanks! you are genious!
from russia with love)

Anonymous said...

Thank you for this hint, it works great!

Anonymous said...

I followed the steps posted by Shawn Lindsey, and it works. Thanks for the help. I was getting frustrated before following your steps.

Greatly appreciated.

rs said...

Many thanks!