You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Has anyone been able to spawn ruby subprocesses running different versions of ruby than the parent process?
I'm running rbenv 0.4.0-20-ga7da069 on Mac OS X 10.6.8.
I'm trying to see if the below scenario is feasible. I took over a project where the following was working reliably for some time but after upgrading rbenv, ruby-build, and updating bundler and gem, it broke.
# foo.rb
Dir.chdir("./jruby_project") do
cmd = "bundle exec bin/bar.rb"
IO.popen(cmd, "r").tap {|io| p io.readline}
end
If I call the above foo.rb in a project running ruby-1.9.3 using bundle exec foo.rb, then the above script fails to run ./jruby_project/bin/bar.rb using the version of jruby specified in ./jruby_project/.rbenv-version. Instead, it runs it using ruby-1.9.3.
Inspecting the ENV vars inside of bar.rb shows that RBENV_VERSION, PATH, and a number of other vars show that bar.rb is running using ruby-1.9.3 instead of jruby.
I have tried other ways of spawning a subprocess such as the backtick operator and these result in the same issue.
The text was updated successfully, but these errors were encountered:
Without any editing of the PATH environment variable, you can't spawn different Ruby version subprocesses from a ruby process initiated with rbenv. See #121
I found a fix that doesn't require editing of the PATH environment variable.
Dir.chdir("./jruby_project") do
cmd = "rbenv exec bundle exec bin/bar.rb".split(" ")
IO.popen([{"RBENV_VERSION" => "jruby-1.7.3"}, *cmd], "r").tap {|io| p io.readline}
end
Process.spawn, IO.popen, Open3.popen3, etc. all allow setting env vars. Using rbenv exec allows the subprocess to honor RBENV_VERSION and spawn with a different version than the parent ruby process initiated with rbenv.
Oh, nice workaround for your problem. But I don't want to advise this to everyone, because people shouldn't be using rbenv exec that often (it's a semi-internal command). Also, this makes your script unusable by a teammate who's using a different Ruby version manager than rbenv.
Has anyone been able to spawn ruby subprocesses running different versions of ruby than the parent process?
I'm running rbenv 0.4.0-20-ga7da069 on Mac OS X 10.6.8.
I'm trying to see if the below scenario is feasible. I took over a project where the following was working reliably for some time but after upgrading rbenv, ruby-build, and updating bundler and gem, it broke.
If I call the above
foo.rb
in a project running ruby-1.9.3 usingbundle exec foo.rb
, then the above script fails to run./jruby_project/bin/bar.rb
using the version of jruby specified in./jruby_project/.rbenv-version
. Instead, it runs it using ruby-1.9.3.Inspecting the
ENV
vars inside ofbar.rb
shows thatRBENV_VERSION
,PATH
, and a number of other vars show thatbar.rb
is running using ruby-1.9.3 instead of jruby.I have tried other ways of spawning a subprocess such as the backtick operator and these result in the same issue.
The text was updated successfully, but these errors were encountered: