Tuesday 20 February 2018

command line - Setting multiple environment variables in a shell spawned via windows batch script


I have a batch file that spawns a shell with a modified path with the following command:


cmd /K set PATH=%PATH%;

I want to set additional environment variables for the spawned shell as well. Is there any way to do that?



Answer



Simply add another variable on a new line using set as shown in your example. You will also want to remove the /K switch from the first line as execution will stop after that line.


set NEWVAR=SOMETHING

will create a new variable called NEWVAR with the value SOMETHING. If you wish to keep the same behavior and keep cmd open with the /K switch just put it at the end.


example:


set PATH=%PATH%;C:\Folder;
set NEWVAR=SOMETHING
echo %NEWVAR%

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...