Forum: Ruby Kernel.exec won't find a file that File.expand_path can

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
06fa952559609d00a12ad22d74335282?d=identicon&s=25 Fritz Anderson (fritza)
on 2008-12-08 23:30
I'm doing a fork/exec on a .rb file in the same directory as the parent
.rb. On two systems, this has worked. On the third, to which I just
moved, I get

./ecod-poll:254:in `exec': No such file or directory -
/home/fritza/ecod/mail-tail/ecod-tracker.rb (Errno::ENOENT)

I've put debugging puts'es into the code, and the path I'm using looks
OK. Feeding the path from the puts to "ls -l" shows that the file exists
and is world-readable and world-executable.

Would someone please help me figure this out? No doubt it's something
dumb, but I'm just not seeing it.

===

On the non-working system: ruby 1.8.5 (2006-08-25) [x86_64-linux] |
Rails 2.2.2
On the working system: ruby 1.8.5 (2006-08-25) [x86_64-linux] | Rails
2.0.2

My source on the non-working system is a Subversion checkout of what's
on the working one. Subversion has (I'm pretty sure) successfully
transported between two working systems.

I am also using ActiveRecord standalone, and I'm sure none of the MySQL
and supporting versions match.

===
   while $processQueue.length < MAX_PROCESSES && $requestQueue.length >
0
      messageID = $requestQueue.shift
      pid = fork

      puts "./ecod-tracker.rb ->
#{File.expand_path('./ecod-tracker.rb')}"
      # => ./ecod-tracker.rb ->
/home/fritza/ecod/mail-tail/ecod-tracker.rb
            # ls -l on that path shows an executable file there.
      puts Dir.pwd
      # => /home/fritza/ecod/mail-tail

      exec(File.expand_path('./ecod-tracker.rb'), messageID) if pid.nil?
      # => No such file or directory -
/home/fritza/ecod/mail-tail/ecod-tracker.rb
   end
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2008-12-08 23:54
(Received via mailing list)
On Mon, Dec 8, 2008 at 11:23 PM, Fritz Anderson <fritza@uchicago.edu>
wrote:
At first sight this seems to be a problem with file permissions can
you post the ls -l ? Is it executable for the user running the script,
what would that be for rails? Maybe different for that version?
Maybe you wanna add a
   system("id")
or a Ruby File test for executability to your code?

HTH
Robert


--
Il computer non è una macchina intelligente che aiuta le persone
stupide, anzi, è una macchina stupida che funziona solo nelle mani
delle persone intelligenti.
Computers are not smart to help stupid people, rather they are stupid
and will work only if taken care of by smart people.

Umberto Eco
06fa952559609d00a12ad22d74335282?d=identicon&s=25 Fritz Anderson (fritza)
on 2008-12-09 16:56
Robert Dober wrote:
> On Mon, Dec 8, 2008 at 11:23 PM, Fritz Anderson <fritza@uchicago.edu>
> wrote:
> At first sight this seems to be a problem with file permissions can
> you post the ls -l ? Is it executable for the user running the script,
> what would that be for rails? Maybe different for that version?
> Maybe you wanna add a
>    system("id")
> or a Ruby File test for executability to your code?

Good leads, thanks.

I put in puts'es to verify all these things, and everything looked okay.

But I made a dumb mistake, which I'll document for the archives.

I took the path of the executable for the child process, and pasted it
into the shell. The result was a bash error ending in:

/usr/local/bin/ruby: bad interpreter: No such file or directory

So it was the _interpreter_, not the executable, which was "No such file
or directory." My child executable in fact began with "#!
/usr/local/bin/ruby". Ruby on the new machine is at /usr/bin/ruby.
Changing the shebang to "#! /usr/bin/env ruby" fixed my problem.

(On RHEL5 Linux, "which env" yields /bin/env, but /usr/bin/env does
exist.)

Lesson: When porting your Ruby application to a new machine, make sure
the interpreter line -- the shebang line -- actually points to Ruby. env
is your friend.

Sorry for the noise.
703fbc991fd63e0e1db54dca9ea31b53?d=identicon&s=25 Robert Dober (Guest)
on 2008-12-09 18:37
(Received via mailing list)
On Tue, Dec 9, 2008 at 4:49 PM, Fritz Anderson <fritza@uchicago.edu>
wrote:
> Robert Dober wrote:
Nobody will believe me if I tell you that just after sending my post,
I thought "Oh boy this might as well be the shebang". Therefore I will
not tell you ;).
Just an idea, np for the noise, but maybe you want to post to the
rails list next time it seems still better a place than the ruby list.
Cheers
R.
This topic is locked and can not be replied to.