Skip to content

Commit 056980e

Browse files
authored
Fix 1255-possible-regression-appendenv-in-powershell-fails-if-env-variable-does-not-exist-already (#1285)
* Fix error with Get-ChildItem by silently continuing Signed-off-by: Thorsten Kaufmann <[email protected]>
1 parent 44b3d51 commit 056980e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/rezplugins/shell/_utils/powershell_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,11 @@ def appendenv(self, key, value):
273273

274274
# Be careful about ambiguous case in pwsh on Linux where pathsep is :
275275
# so that the ${ENV:VAR} form has to be used to not collide.
276+
# The nested Get-ChildItem call is set to SilentlyContinue to prevent
277+
# an exception of the Environment Variable is not set already
276278
self._addline(
277-
'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem "Env:{0}").Value + "{1}{2}")'.format(
278-
key, self.pathsep, value)
279-
)
279+
'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value + "{1}{2}")'
280+
.format(key, os.path.pathsep, value))
280281

281282
def unsetenv(self, key):
282283
self._addline(r"Remove-Item Env:\%s" % key)

0 commit comments

Comments
 (0)