How do I source environment variables for a command shell in a Ruby script?
environment-variables, ruby
Solution
Do this:
$ source whatever.sh
$ set > variables.txt
And then in Ruby:
File.readlines("variables.txt").each do |line|
values = line.split("=")
ENV[values[0]] = values[1]
end
After you've ran this, your environment should be good to go.
Problem
I'm trying to run some third party bash scripts from within my ruby program. Before I can run them they require me to source a file. On the command line it all works fine but within Ruby it doesn't work. I've found out that system commands will open a new child shell process and any sourcing will be done in that and can't be seen from the parent shell process running the Ruby script. When the system call ends, the child shell is also killed. How do i get round this problem?