Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script that does something like


echo %PATH%

When I echo the path, it does not include %ANOTHER_VAR%. is there a way to ensure the new variables are reflected the second time I echo %PATH%

EDIT: I'm writing a puppet script that calls 2 separate exec commands. The first calls setx on a variable. Since the second one is accessed in a new exec command, I would expect it to have access to the newly set variable, but it does not.

I have also tried just creating a variable in script1 and accessing that from script2, but it's not accessible (as expected).

share|improve this question
up vote 1 down vote accepted

As I understand it, setx sets the variable via the registry (see this article). It requires the start of a new command shell to see the results.

If you want to change the path setting under the current command session use set path=%path%;%another_variable%.

In response to the comment, this is from setx /?:

NOTE: 1) SETX writes variables to the master environment in the registry.

2) On a local system, variables created or modified by this tool will be available in future command windows but not in the current CMD.exe command window.

If you want to change the variable in the current command session, use plain SET.

Below is the output from my system:

C:\Windows\system32>set path2=%cd%

C:\Windows\system32>set path2

C:\Windows\system32>cd drivers

C:\Windows\System32\drivers>set path2=%path2%;%cd%

C:\Windows\System32\drivers>set path2
share|improve this answer
Hmmm..I must be doing something else wrong. I have one script that is calling the other 2 and the 2nd script does not pick up the changes via setx. I might just be expecting something that shouldn't happen. – Jeff Storey Mar 1 '12 at 3:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .