Richard C
Richard C

Reputation: 411

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

Upvotes: 0

Views: 1316

Answers (1)

Joey
Joey

Reputation: 354714

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.

Upvotes: 3

Related Questions