[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby 1.4.6 - trouble with require path

primehalo

11/5/2004 1:53:00 AM

I inherited a project that uses Ruby 1.4.6 on a RedHat Linux 6.1J. I
copied it onto my RedHat Linux 6.1J machine, but there is a problem
when I try to build it; the ruby scripts are unable to find required
files (located in the same directory as the scripts) when the script
is executed from a different directory. I upgraded to Ruby 1.6.7,
which fixed that problem, but the scripts are not quite compatible
with the updated Ruby, so I had to revert to the version that was
originally used.

As an example, lets say I have two ruby scripts in a directory:
/scripts/script1.rb:
#!/usr/bin/ruby
require "script2"

/scripts/script2.rb:
print "Testing...\n"

Command Prompt:
[testing]# cd /scripts
[scripts]# script1.rb
Testing...
[scripts]# cd /testing
[testing]# script1.rb
script1.rb:2:in `require': No such file to load -- script2
(LoadError)

With Ruby 1.6.7, it works fine. With Ruby 1.4.6, it can find
script1.rb, but not script2.rb.

There must be a way to correct this, as the project apparently worked
for the original developers. I'm using the same OS, and I added the
same ruby options and script directory to my path as specified in
their readme (well almost, they said put it in .cshrc, but I had to
put it in .tcshrc for it to work):
setenv RUBYOPT '-Ke -rkconv'
set path = ( $path /scripts)

I also tried the following:
setenv RUBYOPT '-Ke -rkconv -S'
setenv LOAD_PATH /scripts
setenv RUBYLIB /scripts

So what am I missing here? Does anyone know how I can get this to work
correctly WITHOUT ALTERING THE SCRIPTS (because there are hundreds of
scripts)?
11 Answers

Ara.T.Howard

11/5/2004 2:25:00 AM

0

David Ross

11/5/2004 2:37:00 AM

0

Ara.T.Howard@noaa.gov wrote:

> On Thu, 4 Nov 2004, Ken Innes wrote:
>
>> I inherited a project that uses Ruby 1.4.6 on a RedHat Linux 6.1J. I
>> copied it onto my RedHat Linux 6.1J machine, but there is a problem
>> when I try to build it; the ruby scripts are unable to find required
>> files (located in the same directory as the scripts) when the script
>> is executed from a different directory. I upgraded to Ruby 1.6.7,
>> which fixed that problem, but the scripts are not quite compatible
>> with the updated Ruby, so I had to revert to the version that was
>> originally used.
>>
>> As an example, lets say I have two ruby scripts in a directory:
>> /scripts/script1.rb:
>> #!/usr/bin/ruby
>> require "script2"
>>
>> /scripts/script2.rb:
>> print "Testing...\n"
>>
>> Command Prompt:
>> [testing]# cd /scripts
>> [scripts]# script1.rb
>> Testing...
>> [scripts]# cd /testing
>> [testing]# script1.rb
>> script1.rb:2:in `require': No such file to load -- script2
>> (LoadError)
>>
>> With Ruby 1.6.7, it works fine. With Ruby 1.4.6, it can find
>> script1.rb, but not script2.rb.
>>
>> There must be a way to correct this, as the project apparently worked
>> for the original developers. I'm using the same OS, and I added the
>> same ruby options and script directory to my path as specified in
>> their readme (well almost, they said put it in .cshrc, but I had to
>> put it in .tcshrc for it to work):
>> setenv RUBYOPT '-Ke -rkconv'
>> set path = ( $path /scripts)
>>
>> I also tried the following:
>> setenv RUBYOPT '-Ke -rkconv -S'
>> setenv LOAD_PATH /scripts
>> setenv RUBYLIB /scripts
>>
>> So what am I missing here? Does anyone know how I can get this to work
>> correctly WITHOUT ALTERING THE SCRIPTS (because there are hundreds of
>> scripts)?
>
>
> i can't help you at all, but i'm dying to know: what project have you
> inherited with hundreds of 1.4.6?
>
> -a
> --

heh, I'm suprised they kept that many scripts without adjusting to other
releases. I'm curious myself as well. Insane it is =]

David Ross
--
Hazzle free packages for Ruby?
RPA is available from http://www.rubyar...



Eric Hodel

11/5/2004 6:17:00 AM

0

Ken Innes (primehalo@hotmail.com) wrote:

> I inherited a project that uses Ruby 1.4.6 on a RedHat Linux 6.1J. I
> copied it onto my RedHat Linux 6.1J machine, but there is a problem
> when I try to build it; the ruby scripts are unable to find required
> files (located in the same directory as the scripts) when the script
> is executed from a different directory. I upgraded to Ruby 1.6.7,
> which fixed that problem, but the scripts are not quite compatible
> with the updated Ruby, so I had to revert to the version that was
> originally used.
>
> As an example, lets say I have two ruby scripts in a directory:
> /scripts/script1.rb:
> #!/usr/bin/ruby
> require "script2"
>
> /scripts/script2.rb:
> print "Testing...\n"
>
> Command Prompt:
> [testing]# cd /scripts
> [scripts]# script1.rb
> Testing...
> [scripts]# cd /testing
> [testing]# script1.rb
> script1.rb:2:in `require': No such file to load -- script2
> (LoadError)
>
> With Ruby 1.6.7, it works fine. With Ruby 1.4.6, it can find
> script1.rb, but not script2.rb.

While I believe you, I don't see how ruby can see from /testing into
/scripts.

> There must be a way to correct this, as the project apparently worked
> for the original developers. I'm using the same OS, and I added the
> same ruby options and script directory to my path as specified in
> their readme (well almost, they said put it in .cshrc, but I had to
> put it in .tcshrc for it to work):
> setenv RUBYOPT '-Ke -rkconv'
> set path = ( $path /scripts)
>
> I also tried the following:
> setenv RUBYOPT '-Ke -rkconv -S'
> setenv LOAD_PATH /scripts

> setenv RUBYLIB /scripts
^^^^^^^^^^^^^^^^^^^^^^^

This should do the trick.

You can verify this with something like:

cd /testing

ruby14 -e 'p $:' -r /scripts/script1.rb

/scripts should be the first thing in the array.

> So what am I missing here? Does anyone know how I can get this to work
> correctly WITHOUT ALTERING THE SCRIPTS (because there are hundreds of
> scripts)?

PS: I now have a ruby14 installed!

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

Brian Candler

11/5/2004 9:44:00 AM

0

> PS: I now have a ruby14 installed!

If you go to the list archive at
http://blade.nagaokaut.ac.jp/ruby/ruby-talk/i...
and do a "(Subjects, Regular Expression)" search, the bottom of the second
frame still carries a graphic saying:

"Ruby 1.1: Enjoy Multi-thread Programming by Ruby."

:-)


primehalo

11/6/2004 4:01:00 AM

0

David Ross <dross@code-exec.net> wrote in message news:<418AE839.9040401@code-exec.net>...
> Ara.T.Howard@noaa.gov wrote:
>
> > On Thu, 4 Nov 2004, Ken Innes wrote:
> >
> >> I inherited a project that uses Ruby 1.4.6 on a RedHat Linux 6.1J. I
> >> copied it onto my RedHat Linux 6.1J machine, but there is a problem
> >> when I try to build it; the ruby scripts are unable to find required
> >> files (located in the same directory as the scripts) when the script
> >> is executed from a different directory. I upgraded to Ruby 1.6.7,
> >> which fixed that problem, but the scripts are not quite compatible
> >> with the updated Ruby, so I had to revert to the version that was
> >> originally used.
> >>
> >> As an example, lets say I have two ruby scripts in a directory:
> >> /scripts/script1.rb:
> >> #!/usr/bin/ruby
> >> require "script2"
> >>
> >> /scripts/script2.rb:
> >> print "Testing...\n"
> >>
> >> Command Prompt:
> >> [testing]# cd /scripts
> >> [scripts]# script1.rb
> >> Testing...
> >> [scripts]# cd /testing
> >> [testing]# script1.rb
> >> script1.rb:2:in `require': No such file to load -- script2
> >> (LoadError)
> >>
> >> With Ruby 1.6.7, it works fine. With Ruby 1.4.6, it can find
> >> script1.rb, but not script2.rb.
> >>
> >> There must be a way to correct this, as the project apparently worked
> >> for the original developers. I'm using the same OS, and I added the
> >> same ruby options and script directory to my path as specified in
> >> their readme (well almost, they said put it in .cshrc, but I had to
> >> put it in .tcshrc for it to work):
> >> setenv RUBYOPT '-Ke -rkconv'
> >> set path = ( $path /scripts)
> >>
> >> I also tried the following:
> >> setenv RUBYOPT '-Ke -rkconv -S'
> >> setenv LOAD_PATH /scripts
> >> setenv RUBYLIB /scripts
> >>
> >> So what am I missing here? Does anyone know how I can get this to work
> >> correctly WITHOUT ALTERING THE SCRIPTS (because there are hundreds of
> >> scripts)?
> >
> >
> > i can't help you at all, but i'm dying to know: what project have you
> > inherited with hundreds of 1.4.6?
> >
> > -a
> > --
>
> heh, I'm suprised they kept that many scripts without adjusting to other
> releases. I'm curious myself as well. Insane it is =]
>
> David Ross

Can't go into details, but it's a project from Japan that was finished
years ago, probably when version 1.4.6 was current, or at least
near-current.

primehalo

11/6/2004 5:17:00 AM

0

Well, "setenv RUBYLIB /scripts" was the right solution. I don't quite
understand what was going on; RUBYLIB was set (as verified by typing
"setenv"), but Ruby couldn't find the scripts until I restarted the
computer. Then it seemed to work fine.

But now I'm having another weird problem where accessing the PATH
environment variable is causing Ruby not find scripts. For example:
/scripts/script1.rb:
#!/usr/bin/ruby
print `script3.rb`

/scripts/script2.rb:
#!/usr/bin/ruby
ENV["PATH"].split(/:/).each { |i|
#do nothing
}
print `script3.rb`

/scripts/script3.rb:
#!/usr/bin/ruby
print "Testing...\n"

Command Prompt:
[scripts]# cd /testing
[testing]# script1.rb
Testing....
[testing]# script2.rb
/testing/script2:4: command not found: script3

Any access to ENV["PATH"] seems to cause the problem, for example:
print ENV["PATH"]
tmp = ENV["PATH"]
ENV["PATH"].chomp!

Any ideas on this one?

Eric Hodel

11/6/2004 7:36:00 AM

0

Ken Innes (primehalo@hotmail.com) wrote:

> Well, "setenv RUBYLIB /scripts" was the right solution. I don't quite
> understand what was going on; RUBYLIB was set (as verified by typing
> "setenv"), but Ruby couldn't find the scripts until I restarted the
> computer. Then it seemed to work fine.
>
> But now I'm having another weird problem where accessing the PATH
> environment variable is causing Ruby not find scripts. For example:
> /scripts/script1.rb:
> #!/usr/bin/ruby
> print `script3.rb`
>
> /scripts/script2.rb:
> #!/usr/bin/ruby
> ENV["PATH"].split(/:/).each { |i|
> #do nothing
> }
> print `script3.rb`
>
> /scripts/script3.rb:
> #!/usr/bin/ruby
> print "Testing...\n"
>
> Command Prompt:
> [scripts]# cd /testing
> [testing]# script1.rb
> Testing....
> [testing]# script2.rb
> /testing/script2:4: command not found: script3
>
> Any access to ENV["PATH"] seems to cause the problem, for example:
> print ENV["PATH"]
> tmp = ENV["PATH"]
> ENV["PATH"].chomp!
>
> Any ideas on this one?

Looking at the code for ENV.[], I don't see anything that would cause
this, unless there's some bug in your libc with getenv.

Perhaps you should try a bash-like shell instead of a csh-like shell?

Oh, try this:

puts ENV["PATH"]
puts `env | grep path`

See if your PATH is really destroyed.

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

primehalo

11/8/2004 9:26:00 PM

0

Eric Hodel <drbrain@segment7.net> wrote in message news:<20041106073536.GK93473@segment7.net>...
> Ken Innes (primehalo@hotmail.com) wrote:
>
> > Well, "setenv RUBYLIB /scripts" was the right solution. I don't quite
> > understand what was going on; RUBYLIB was set (as verified by typing
> > "setenv"), but Ruby couldn't find the scripts until I restarted the
> > computer. Then it seemed to work fine.
> >
> > But now I'm having another weird problem where accessing the PATH
> > environment variable is causing Ruby not find scripts. For example:
> > /scripts/script1.rb:
> > #!/usr/bin/ruby
> > print `script3.rb`
> >
> > /scripts/script2.rb:
> > #!/usr/bin/ruby
> > ENV["PATH"].split(/:/).each { |i|
> > #do nothing
> > }
> > print `script3.rb`
> >
> > /scripts/script3.rb:
> > #!/usr/bin/ruby
> > print "Testing...\n"
> >
> > Command Prompt:
> > [scripts]# cd /testing
> > [testing]# script1.rb
> > Testing....
> > [testing]# script2.rb
> > /testing/script2:4: command not found: script3
> >
> > Any access to ENV["PATH"] seems to cause the problem, for example:
> > print ENV["PATH"]
> > tmp = ENV["PATH"]
> > ENV["PATH"].chomp!
> >
> > Any ideas on this one?
>
> Looking at the code for ENV.[], I don't see anything that would cause
> this, unless there's some bug in your libc with getenv.
>
> Perhaps you should try a bash-like shell instead of a csh-like shell?
>
> Oh, try this:
>
> puts ENV["PATH"]
> puts `env | grep path`
>
> See if your PATH is really destroyed.

My default shell is bash, but I change to csh to run their scripts (as
that's what it said to do in their readme file). Still, I have tried
it in both shells with the same results.

Anyway, I tried your suggestion, and here's what happens:

Try 1:
/scripts/script2.rb:
#!/usr/bin/ruby
puts ENV["PATH"]
puts `env | grep path`

Command Line:
[testing]% script2.rb
/bin:/usr
sh: env: command not found
[testing]%

Didn't work because I referenced ENV["PATH"] so it couldn't find
"env".

Try 2:
/scripts/script2.rb:
#!/usr/bin/ruby
puts ENV["PATH"]
puts `/usr/bin/env | grep path`

Command Line:
[testing]% script2.rb
/bin:/usr

[testing]%

Probably put a blank line because of a difference in case.

Try 3:
/scripts/script2.rb:
#!/usr/bin/ruby
puts ENV["PATH"]
puts `/usr/bin/env | grep PATH`

Command Line:
[testing]% script2.rb
/bin:/usr
PATH=/bin:/usr
[testing]%

The PATH environment variable still seems to be in tact, but Ruby
still can't find any files that are in PATH directories after
ENV["PATH"] is accessed.

primehalo

11/8/2004 10:51:00 PM

0

Oops, actually, my path did get messed up. I didn't notice before
(must be Monday), but there are several directories missing from the
PATH, including the /scripts directory. So I just did another test:

/scripts/script2.rb:
#!/usr/bin/ruby
puts `env | grep PATH`
puts ENV["PATH"]
puts `/usr/bin/env | grep PATH`

Command Line:
[testing]% script2.rb
/bin:/usr/bin:/usr/local/bin:.:/scripts
/bin:/usr
PATH=/bin:/usr
[testing]%

And I notice that there is no "/usr" initially, but it's there after
the ENV["PATH"] is referenced. I've searched all the files in my home
directory, and don't see it setting just "/usr" to the path anywhere.
I also search through the files in the Ruby directory, and also never
see a "/usr" by itself.

Eric Hodel

11/9/2004 1:40:00 AM

0

On Nov 8, 2004, at 2:53 PM, Ken Innes wrote:

> Oops, actually, my path did get messed up. I didn't notice before
> (must be Monday), but there are several directories missing from the
> PATH, including the /scripts directory. So I just did another test:
>
> /scripts/script2.rb:
> #!/usr/bin/ruby
> puts `env | grep PATH`
> puts ENV["PATH"]
> puts `/usr/bin/env | grep PATH`
>
> Command Line:
> [testing]% script2.rb
> /bin:/usr/bin:/usr/local/bin:.:/scripts
> /bin:/usr
> PATH=/bin:/usr
> [testing]%
>
> And I notice that there is no "/usr" initially, but it's there after
> the ENV["PATH"] is referenced. I've searched all the files in my home
> directory, and don't see it setting just "/usr" to the path anywhere.
> I also search through the files in the Ruby directory, and also never
> see a "/usr" by itself.

Hrm...

I'm not sure what the equivalent is on RedHat, but what about looking
/etc/csh.*

There should be default a default .cshrc and .login there, do they have
any odd paths?