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 script that does something like

setx %PATH% %PATH%;%ANOTHER_VAR%

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

1 Answer 1

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
path2=C:\Windows\system32

C:\Windows\system32>cd drivers

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

C:\Windows\System32\drivers>set path2
path2=C:\Windows\system32;C:\Windows\System32\drivers
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

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.