# Kernel.exec won't find a file that File.expand\_path can

**URL:** <https://www.ruby-forum.com/t/kernel-exec-wont-find-a-file-that-file-expand-path-can/155170>\
**Category:** Ruby\
**Created:** [December 8, 2008, 11:30pm UTC](https://www.ruby-forum.com/t/kernel-exec-wont-find-a-file-that-file-expand-path-can/155170 "2008-12-08T23:30:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fritza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5f9b8f/32.png) [@fritza](https://www.ruby-forum.com/u/fritza)\
**Post date:** [December 8, 2008, 11:30pm UTC](https://www.ruby-forum.com/t/kernel-exec-wont-find-a-file-that-file-expand-path-can/155170/1 "2008-12-08T23:30:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fritza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5f9b8f/32.png) [@fritza](https://www.ruby-forum.com/u/fritza)\
**Post date:** [December 8, 2008, 11:54pm UTC](https://www.ruby-forum.com/t/kernel-exec-wont-find-a-file-that-file-expand-path-can/155170/2 "2008-12-08T23:54:27Z")

</div>

On Mon, Dec 8, 2008 at 11:23 PM, Fritz A. [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![fritza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5f9b8f/32.png) [@fritza](https://www.ruby-forum.com/u/fritza)\
**Post date:** [December 9, 2008, 4:56pm UTC](https://www.ruby-forum.com/t/kernel-exec-wont-find-a-file-that-file-expand-path-can/155170/3 "2008-12-09T16:56:20Z")

</div>

Robert D. wrote:

> On Mon, Dec 8, 2008 at 11:23 PM, Fritz A. [removed\_email\_address@domain.invalid](mailto: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.

---

<div class="post-metadata">

**Author:** ![fritza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5f9b8f/32.png) [@fritza](https://www.ruby-forum.com/u/fritza)\
**Post date:** [December 9, 2008, 6:37pm UTC](https://www.ruby-forum.com/t/kernel-exec-wont-find-a-file-that-file-expand-path-can/155170/4 "2008-12-09T18:37:25Z")

</div>

On Tue, Dec 9, 2008 at 4:49 PM, Fritz A. [removed\_email\_address@domain.invalid](mailto: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.
