Passing environment variables to a process in PowerShell 2.0 when the variable is changed multiple times -
i'm having issue when comes passing corresponding environment variables process. below can see part of code can understand i'm trying do.
i have 2 exe files need run. processes run updates based on location of environment variable %mainfiles%
. when run code seems exe files not recognize change. however, when under computer properties see variables changed correctly.
does know how force process recognize change? thanks
while ($i -lt $size) { if ($tempenv[$i] -eq "done"){ $exitcode="completed" return } else { $temp = $tempenv[$i] write-host ("starting update " + $temp) -foregroundcolor "green" [system.environment]::setenvironmentvariable("mainfiles", "$temp","machine") [system.environment]::getenvironmentvariable("mainfiles","machine") copy-item $copyinstalldata -destination $temp $process = start-process xmlupgrade.exe -workingdirectory "c:\program files\dtm" -wait $process = start-process update.exe -workingdirectory "c:\program files\dtm" -wait . . .
this line makes env var change permanent:
[system.environment]::setenvironmentvariable("mainfiles", "$temp","machine")
unfortunately powershell has launched before set this. env block snapshotted @ launch time. environment 2 spawned processes inherit.
to 2 processes launch correct environment variable value first:
$env:mainfiles = $temp
Comments
Post a Comment