Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change of ENV['PATH'] does not work #3247

Closed
maxmeyer opened this issue Aug 12, 2015 · 3 comments
Closed

Change of ENV['PATH'] does not work #3247

maxmeyer opened this issue Aug 12, 2015 · 3 comments
Milestone

Comments

@maxmeyer
Copy link

It's not possible to change the value of ENV['PATH'] from a ruby script. This makes childprocess fail to start commands when the PATH is changed from within a ruby script. Even adding new variables

Please create a file named "env-test.rb" with the following content:

ENV["PATH"] = "/foo:#{ENV["PATH"]}"
ENV["VAR"] = "asdf"

puts java.lang.System.getenv("PATH").to_s.include?("/foo:") #=> false
puts java.lang.System.getenv("VAR").to_s.include?("asdf") #=> false

puts ENV["PATH"].to_s.include?("/foo:") #=> true
puts ENV["VAR"].to_s.include?("asdf") #=> true

Then run the file with:

jruby --dev env-test.rb

According to @jarib the result should be "true" for

puts java.lang.System.getenv("PATH").to_s.include?("/foo:") #=> false
puts java.lang.System.getenv("VAR").to_s.include?("asdf") #=> false

but is "false".

This is related to enkessler/childprocess#89 and maybe even related to http://stackoverflow.com/questions/10035383/setting-the-environment-for-processbuilder.

Pinging @jarib and @mattwynne.

@mkristian
Copy link
Member

you can not change the environment variable from java. that is why ENV['PATH'] = something has no effect on the java side.

but executing a "child process" from jruby works as expect:

$ bin/jruby -v -e 'ENV["PATH"]="Asd"; puts `echo $PATH`'
jruby 9.0.1.0-SNAPSHOT (2.2.2) 2015-07-31 53aef42 Java HotSpot(TM) 64-Bit Server VM 25.51-b03 on 1.8.0_51-b16 +jit [darwin-x86_64]
Asd

without knowing but first I would try the MRI on jruby-9k. I should/could work.

if you go the java route then you need to find a way to tell the ProcessBuilder to use a new environment.

@maxmeyer
Copy link
Author

@jarib Can you help here? We're just users of jarib/childprocess? What do you suggest?

without knowing but first I would try the MRI on jruby-9k. I should/could work.

What do you mean with this? The problem I ran into with ChildProcess occures with 1.7 and 9.0. ChildProcess with ProcessBuilder in the background does not find the command because the PATH needs to be modified from ruby during runtime.

@kares
Copy link
Member

kares commented Aug 14, 2015

as noted at enkessler/childprocess#89 you can NOT expect ENV modifications to be reflected on the JVM level with java.lang.System.getenv as it's by design read-only. you should experiment with avoiding the underlying ProcessBuilder under JRuby and use the same as MRI (although ONLY on JRuby 9.0.0.0)

@kares kares added this to the Won't Fix milestone Aug 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants