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

Discussion in 'Ruby' started by Fritz Anderson, Dec 8, 2008.

  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
    --
    Posted via http://www.ruby-forum.com/.
    Fritz Anderson, Dec 8, 2008
    #1
    1. Advertising

  2. Fritz Anderson

    Robert Dober Guest

    On Mon, Dec 8, 2008 at 11:23 PM, Fritz Anderson <> 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


    --=20
    Il computer non =E8 una macchina intelligente che aiuta le persone
    stupide, anzi, =E8 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
    Robert Dober, Dec 8, 2008
    #2
    1. Advertising

  3. Robert Dober wrote:
    > On Mon, Dec 8, 2008 at 11:23 PM, Fritz Anderson <>
    > 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.


    --
    Posted via http://www.ruby-forum.com/.
    Fritz Anderson, Dec 9, 2008
    #3
  4. Fritz Anderson

    Robert Dober Guest

    On Tue, Dec 9, 2008 at 4:49 PM, Fritz Anderson <> 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.
    Robert Dober, Dec 9, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yogesh
    Replies:
    3
    Views:
    574
    Kenny McCormack
    Feb 12, 2006
  2. Alan Davies

    File.expand_path and ~ on windows

    Alan Davies, Sep 18, 2003, in forum: Ruby
    Replies:
    2
    Views:
    140
    Alan Davies
    Sep 22, 2003
  3. Replies:
    3
    Views:
    159
  4. Alpha Blue
    Replies:
    25
    Views:
    273
    Robert Klemme
    Feb 5, 2010
  5. Lars Gierth
    Replies:
    6
    Views:
    212
    David Masover
    Mar 20, 2010
Loading...

Share This Page