Project

General

Profile

Bug #8004

spawn does not honor its passed PATH

Added by Josh Cheek almost 4 years ago. Updated 29 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
ruby -v:
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]
[ruby-core:53103]

Description

#!/bin/sh

# make an executable
  echo '#!/usr/bin/env ruby' >  my_bin
  echo 'puts "omg"'          >> my_bin
  chmod +x my_bin


# run it in 1.9
  ruby1.9 -v
    # >> ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]

  ruby1.9 -r open3 -e 'p Open3.capture3({"PATH" => ".:#{ENV["PATH"]}"}, "my_bin")'
    # >> ["omg\n", "", #<Process::Status: pid 30556 exit 0>]

# run it in 2.0
  ruby2 -v
    # >> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

  ruby2 -r open3 -e 'p Open3.capture3({"PATH" => ".:#{ENV["PATH"]}"}, "my_bin")'
    # >> /Users/joshcheek/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open3.rb:211:in `spawn': No such file or directory - my_bin (Errno::ENOENT)
    # >>   from /Users/joshcheek/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open3.rb:211:in `popen_run'
    # >>   from /Users/joshcheek/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open3.rb:99:in `popen3'
    # >>   from /Users/joshcheek/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open3.rb:279:in `capture3'
    # >>   from -e:1:in `<main>'

  # the above fails, but this one works
  ruby2 -r open3 -e 'ENV["PATH"] = ".:#{ENV["PATH"]}"; p Open3.capture3("my_bin")'
    # >> ["omg\n", "", #<Process::Status: pid 30556 exit 0>]

  # it is setting the path, though, so idk what the problem is
  ruby2 -r open3 -e 'p Open3.capture3({"PATH" => ".:#{ENV["PATH"]}"}, "echo $PATH")'
    # >> [".:/Users/joshcheek/.rbenv/shims: ...

Associated revisions

Revision 56618
Added by Nobuyoshi Nakada 29 days ago

process.c: PATH env in spawn

  • process.c (rb_exec_fillarg): honor the given path environment variable. [Bug #8004]

History

#1 [ruby-core:53104] Updated by Josh Cheek almost 4 years ago

Did some more digging, it seems to be a bug in Process.spawn:

#!/bin/sh

cat script.rb
  # >> File.write 'my_bin', 'echo "WORKS"'
  # >> File.chmod 0755, 'my_bin'
  # >>
  # >> puts "CWD: #{Dir.pwd}"
  # >> Process.spawn({'PATH' => ".:#{ENV['PATH']}"}, 'my_bin')


ruby1.9 -v
  # >> ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0]
ruby1.9 script.rb
  # >> CWD: /Users/joshcheek/deleteme/ruby2-bug-test
  # >> WORKS

ruby2 -v
  # >> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

ruby2 script.rb
  # >> CWD: /Users/joshcheek/deleteme/ruby2-bug-test
  # >> script.rb:5:in `spawn': No such file or directory - my_bin (Errno::ENOENT)
  # >>   from script.rb:5:in `<main>'

#2 [ruby-core:77858] Updated by Josh Cheek about 1 month ago

On my computer, the reason for this is:

It should have found the path here: https://github.com/ruby/ruby/blob/c7e99cbfc8dea00ffa5d0a286ea484e90e789df4/process.c#L2193

But notice the second argument, 0, which causes dln_find_exe_r to look at the environment variables to get the PATH, and thus the PATH that is set in eargp is not used.

#3 [ruby-core:77859] Updated by Shyouhei Urabe about 1 month ago

  • Subject changed from Open3 not finding binaries when PATH env var is passed as first arg to spawn does not honor its passed PATH

#4 Updated by Nobuyoshi Nakada 29 days ago

  • Status changed from Open to Closed

Applied in changeset r56618.


process.c: PATH env in spawn

  • process.c (rb_exec_fillarg): honor the given path environment variable. [Bug #8004]

#5 Updated by Nobuyoshi Nakada 29 days ago

  • Description updated (diff)

Also available in: Atom PDF