Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporarily set Environment variables with batch file

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?

like image 379
Camel89 Avatar asked Nov 05 '15 11:11

Camel89


People also ask

How do I set an environment variable temporarily?

Environment variables can be defined temporarily by booting to MS-DOS mode, defining variables with the SET command and then starting Windows. Variables defined in this way persist until the system is rebooted.

How do I set environment variable in CMD?

To set (or change) a environment variable, use command " set varname=value ". There shall be no spaces before and after the '=' sign. To unset an environment variable, use " set varname= ", i.e., set it to an empty string.

What is %% A in batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


1 Answers

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

like image 115
Greg Avatar answered Oct 23 '22 05:10

Greg