I have a bunch of batch files which I want to run sequentially. One of them runs an MSI which adds a folder to the PATH
. How can I make sure that subsequent batch files will notice this change, without restarting CMD? I'm using Windows Server 2008 R2 x64.
I've tried call
, cmd /c
and start ""
, in the hope that starting a new process will work, but it doesn't.
in run-both-scripts.bat
call script1.bat <-- This runs an MSI which modifies the PATH
call script2.bat <-- This relies on the PATH changes which were made by the MSI in script1.bat
To clarify: this is fairly straightforward to reproduce.
- Start CMD
- Create an environment variable manually, not using
setx
, to mimic what the MSI does.- Right click on Computer -> Properties -> Advanced System Settings -> Environment variables -> New
- Create an environment variable called, say,
hello
with the valuehi there
.
- In your CMD window, type
echo %hello%
. You'll get%hello%
. - Try
cmd /c "echo %hello%
. You'll get%hello%
. - Try
start ""
to open a new CMD process; typeecho %hello%
. You'll get%hello%
. - Try
start "" echo %hello%
to run the command in a new CMD process. You'll get%hello%
. - Finally, try manually opening a new CMD window from the Start menu and type
echo %hello%
from there. You'll seehi there
.
So you can see that the only way I've been able to make CMD see the change to the environment variable is by restarting CMD.