Shell out from ruby while setting an environment variable

前端 未结 5 488
囚心锁ツ
囚心锁ツ 2020-12-06 16:04

I need to shell out to a process while setting an environment variable for it. I tried this one-liner:

system \"RBENV_VERSION=system ruby extconf.rb\"
         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 16:45

    Actually that worked for me.

    shai@comp ~ » irb                                                                                                                                     
    1.9.3p0 :001 > system %{SHAIGUITAR=exists ruby -e 'puts ENV["SHAIGUITAR"]'}
    exists
     => true 
    

    But if it doesn't, maybe you can try prepending "env" to whatever variable you need. E.g.

    system(%{env SHAIGUITAR=exists ruby bla.rb})
    

提交回复
热议问题