How do I source environment variables for a command shell in a Ruby script?

后端 未结 5 1694
野趣味
野趣味 2021-01-01 00:32

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 wor

5条回答
  •  忘掉有多难
    2021-01-01 01:00

    This is horrible, but..

    env = %x{. /some/shell/script/which/setups/your/env && env}
    env.split("\n").each do |line|
      key, value = line.split("=", 2)
      ENV[key] ||= value unless value.nil? or value.empty?
    end
    

提交回复
热议问题