Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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%
share|improve this answer
    
Thanks - that worked like I wanted it to. I put cmd /K at the end because I wanted to use the shell after it had finished executing my commands. –  quanticle Aug 15 '09 at 1:10
1  
You can also write a batch that makes all necessary changes to the environment and then simply start your cmd instance with cmd /k setvars.cmd. This is for example how Visual Studio sets up its command prompt. –  Joey Aug 15 '09 at 12:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.