6

I'd like temporarily set Environment variables like Catalina and Java_Home using a batch file, without making persistent changes.

Changes should be removed after the execution of a web-page.

There's a way to do it?

Camel89
  • 61
  • 1
  • 2
  • 5
    All variables you create in a batch file are volatile when using the SET command. They will all disappear after the batch file closes. – Squashman Nov 05 '15 at 14:09
  • 1
    Well, after the command prompt that had the script running in it closes (just in case you ran the script from the command line instead of double-clicking it). – SomethingDark Nov 05 '15 at 16:11
  • 4
    `setlocal` is generally good practice as well. Changes to variables made within a `setlocal` session are forgotten when the script ends or `endlocal` is encountered. As a bonus, [`setlocal` also preserves](http://stackoverflow.com/a/15659309/1683264) the current working directory. – rojo Nov 05 '15 at 16:16
  • Yes. Setlocal/endlocal is a best practice in my book – Squashman Nov 06 '15 at 02:13

1 Answers1

5

In your file, at the top, use setlocal, when exiting the file, use endlocal.

Greg
  • 3,326
  • 2
  • 16
  • 38