简体   繁体   中英

why 'unset http_proxy' doesn't work in Rakefile

'unset http_proxy' or 'unset HTTP_PROXY' doesnt work in the Rakefile with following two scenerios where other bash commands work succesfully

*file format : Rakefile

Scenerio 1:

 desc "Remove HTTP  Proxy"
 task :remove_http do

 puts "removing HTTP  Proxy..."
 sh "unset HTTP_PROXY"
 puts"Removed HTTP & HTTPS Porxy"
 puts "Showing Environment Variables"
 sh "env"

end

Scenario 2:

 desc "Remove HTTP Proxy"
 task :remove_http do

 puts "removing HTTP Proxy..."
`unset HTTP_PROXY`
 puts"Removed HTTP Porxy"
 puts "Showing Environment Variables"
 sh "env"

end

Any Idea how to solve or that bash command for unsetting HTTP_PROXY will be succesfull in ruby Rakefile ?

To elaborate what Joe mentioned,

when you execute something with sh, your launching a different shell/session than what your ruby program is running in.

In this case, you unset HTTP_PROXY in a session. Then you show the environment in a different session. And there is a third session which is running your ruby program.

If you want to unset HTTP_PROXY, Try doing this

p ENV['HTTP_PROXY'] # See if it's there
ENV.delete('HTTP_PROXY')
p ENV['HTTP_PROXY'] # See if it's gone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM