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

后端 未结 5 1652
野趣味
野趣味 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 00:55

    Modifying ENV works only for a single thread and I do the below instead. But a question I have how do I use a merged COPY of the environment with IO.popen ? somehow it doesn't seem to work.

    with "system" I can do:

    # ... create new "path" here
    
        subEnv = Hash.new;
        subEnv.merge!(ENV); # copy old environment
        subEnv['PATH'] = path; # set new values in copy
    
        system(subEnv, commandLine);
    

提交回复
热议问题