Ruby 1.4.6 - trouble with require path

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

···

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)?

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
When you do something, you should burn yourself completely, like a good
bonfire, leaving no trace of yourself. --Shunryu Suzuki

===============================================================================

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!

···

Ken Innes (primehalo@hotmail.com) wrote:

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

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

···

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
--

--
Hazzle free packages for Ruby?
RPA is available from http://www.rubyarchive.org/

PS: I now have a ruby14 installed!

If you go to the list archive at
  http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml
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."

:slight_smile:

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?

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.

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.

···

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?

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

Eric Hodel <drbrain@segment7.net> wrote in message news:<20041106073536.GK93473@segment7.net>...

> 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.

···

Ken Innes (primehalo@hotmail.com) 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?

···

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.

I did more testing, and found that the path is getting truncated after
"/bin:/usr". My .tcshrc looked like so:
     set path = ( /bin )
     set path = ( $path /usr/bin )
     set path = ( $path /usr/local/bin )
     set path = ( $path . )
     set path = ( $path /scripts )

Then I added a few lines, and it still truncated at the same spot:
     set path = ( /bin )
     set path = ( $path /test1/usr )
     set path = ( $path /test1/usr/test2 )
     set path = ( $path /usr/bin )
     set path = ( $path /usr/local/bin )
     set path = ( $path . )
     set path = ( $path /scripts )

Gave this after executing the script:
     PATH=/bin:/test1/usr:/test1/usr/test2:/usr

However, it does not seem to truncate at all if put /usr as the first
one:
     set path = ( /usr )
     set path = ( $path /bin )
     set path = ( $path /usr/bin )
     set path = ( $path /usr/local/bin )
     set path = ( $path . )
     set path = ( $path /scripts )

I really don't understand this at all.