I have a batch file that spawns a shell with a modified path with the following command:
cmd /K set PATH=%PATH%;<additional path locations>
I want to set additional environment variables for the spawned shell as well. Is there any way to do that?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
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.
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.
set PATH=%PATH%;C:\Folder; set NEWVAR=SOMETHING echo %NEWVAR%
You could also combine them into a single line as follows:
set A=foo & B=bar & C=baz
This way, you could avoid having to modify the original script and run it like so:
set A=foo & B=bar & C=baz & c:\path\to\foo.bat