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


#1

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


#2

On Mon, Dec 8, 2008 at 11:23 PM, Fritz A. removed_email_address@domain.invalid
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


#3

Robert D. wrote:

On Mon, Dec 8, 2008 at 11:23 PM, Fritz A. removed_email_address@domain.invalid
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.


#4

On Tue, Dec 9, 2008 at 4:49 PM, Fritz A. removed_email_address@domain.invalid
wrote:

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