如何在不关闭CMD的情况下在CMD上重新加载Windows环境变量?
答案 0 :(得分:2)
是
setlocal
... do part of the script
endlocal
setlocal
... do part 2 of the script
endlocal
setlocal
... do part 3 of the script
endlocal
可以根据需要添加任意数量的部件。
缺点是您要保存的环境更改将在endlocal
命令中丢失。
围绕这个
有两种方法setlocal
... do part n of the script
endlocal&set keepme=%keepme%&set keepme2=%keepme2%...
或
setlocal
... do part n of the script
set keepme>>keepmefile.txt
endlocal
for /f "delims=" %%a in (keepmefile.txt) do set %%a
将值keepme
的值保存在文件中,然后在执行endlocal
后重新加载它们。 (我倾向于在我想为此目的保留的变量名上保留$
的前缀)