Ruby 1.4.6 - trouble with require path

K

Ken Innes

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

Ara.T.Howard

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

David Ross

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
 
E

Eric Hodel

--3VRmKSg17yJg2MZg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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.
=20
As an example, lets say I have two ruby scripts in a directory:
/scripts/script1.rb:
#!/usr/bin/ruby
require "script2"
=20
/scripts/script2.rb:
print "Testing...\n"
=20
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)
=20
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 =3D ( $path /scripts)
=20
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!

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--3VRmKSg17yJg2MZg
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQFBixrJMypVHHlsnwQRAvL+AJ9l/z9hsRIMOh04eIGkZSylhq6KiACg3mFS
YEB1XD+Gd/fit/GlMA3mwlw=
=XnGF
-----END PGP SIGNATURE-----

--3VRmKSg17yJg2MZg--
 
K

Ken Innes

David Ross said:
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.
 
K

Ken Innes

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

Eric Hodel

--sdEQJo40s7ofW8iR
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
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.
=20
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`
=20
/scripts/script2.rb:
#!/usr/bin/ruby
ENV["PATH"].split(/:/).each { |i|
#do nothing
}
print `script3.rb`
=20
/scripts/script3.rb:
#!/usr/bin/ruby
print "Testing...\n"
=20
Command Prompt:
[scripts]# cd /testing
[testing]# script1.rb
Testing....
[testing]# script2.rb
/testing/script2:4: command not found: script3
=20
Any access to ENV["PATH"] seems to cause the problem, for example:
print ENV["PATH"]
tmp =3D ENV["PATH"]
ENV["PATH"].chomp!
=20
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.

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--sdEQJo40s7ofW8iR
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQFBjH7HMypVHHlsnwQRApbxAJ0ehAFKGy4NMzKDpzn4B7viqcnWkgCfZFbx
qFMpvpY2MOHtszO789ofLU0=
=MCAX
-----END PGP SIGNATURE-----

--sdEQJo40s7ofW8iR--
 
K

Ken Innes

Eric Hodel said:
Ken said:
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.
 
K

Ken Innes

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

Eric Hodel

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

Ken Innes

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top