简体   繁体   English

Windows Batch变量在脚本外部可用

[英]Windows Batch variables available outside a script

I'm creating a script that is to create a variable called http_proxy. 我正在创建一个脚本,该脚本将创建一个名为http_proxy的变量。 The script does a bit more than just set the proxy, it has a few statements in there as well as a prompt for user password on load. 该脚本的作用不只是设置代理,它还包含一些语句以及加载时提示用户输入密码的提示。

I have set up a shortcut to cmd.exe with an extra parameter /k ".set_http_proxy.bat" to run on startup, which sets this variable. 我已经设置了指向cmd.exe的快捷方式,该快捷方式带有一个额外的参数/k ".set_http_proxy.bat"以在启动时运行,该启动器会设置此变量。

Once the script exits, the command prompt remains open for the user to run their scripts. 脚本退出后,命令提示符将保持打开状态,以供用户运行其脚本。 My problem is, the variable http_proxy has vanished now and no trace that it was set in the script that just ran. 我的问题是,变量http_proxy现在消失了,没有在刚刚运行的脚本中设置它的踪迹。

Is there a way to set a variable that will remain in use for that session until the command prompt window is closed? 有没有一种方法可以设置一个变量,该变量在关闭命令提示符窗口之前将一直用于该会话? I think in bash we just use export which is great! 我认为在bash我们只使用export ,这很棒!

current code is simply... 当前代码只是...

set http_proxy=http://proxy.address

If that's all, then it should work exactly as you expect, and in fact it did so for me when I tried it out. 如果仅此而已,那么它应该可以完全按照您的期望工作,实际上,当我尝试时,它对我来说确实如此。

Unless you use setlocal or launch another process for running a batch file, then environment variables persist even after the batch file finishes. 除非您使用setlocal或启动另一个进程来运行批处理文件,否则即使在批处理文件完成之后,环境变量仍将保留。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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