【问题标题】:why 'unset http_proxy' doesn't work in Rakefile为什么 'unset http_proxy' 在 Rakefile 中不起作用
【发布时间】:2018-07-26 13:50:47
【问题描述】:

'unset http_proxy' 或 'unset HTTP_PROXY' 在 Rakefile 中不起作用,以下两个场景是其他 bash 命令成功运行的情况

*文件格式:Rakefile

场景 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

场景 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

任何想法如何解决或取消设置 HTTP_PROXY 的 bash 命令将在 ruby​​ Rakefile 中成功?

【问题讨论】:

  • 当您运行“sh env”时,您将启动与运行 Rake 的 shell 不同的 shell。它们是具有不同环境的两个不同进程。

标签: ruby bash command-line rakefile


【解决方案1】:

为了详细说明乔提到的内容,

当您使用 sh 执行某些操作时,您启动的 shell/会话与运行 ruby​​ 程序的不同。

在这种情况下,您 unset HTTP_PROXY 在会话中。 然后在不同的会话中显示环境。 还有第三个会话正在运行您的 ruby​​ 程序。

如果您想取消设置 HTTP_PROXY, 尝试这样做

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

【讨论】:

  • p ENV['HTTPPROXY'] # 我可以看到代理变量是什么
  • ENV.delete('HTTP_PROXY') # 这个命令在这种情况下不起作用,不知道为什么
  • 哎呀,我的答案肯定错了。确保变量匹配!
  • 我已经尝试了几种方法,正如你所写的,但不幸的是它没有...... :(
猜你喜欢
  • 2012-05-15
  • 2015-09-08
  • 2016-05-23
  • 1970-01-01
  • 1970-01-01
  • 2018-11-28
  • 1970-01-01
  • 2017-10-03
  • 2019-11-27
相关资源
最近更新 更多