简体   繁体   中英

Windows Batch variables available outside a script

I'm creating a script that is to create a variable called 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.

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.

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!

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.

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