【发布时间】:2019-10-01 10:03:45
【问题描述】:
我希望能够从我的 PHP 脚本中访问在 Powershell 中设置的环境变量。
通常在 Linux 系统中 export SOMETHING=foo 可以工作,在 Windows CMD 中 SET SOMETHING=bar 也可以工作。但我不知道如何使用 Powershell CLI(而不是脚本)来完成这项工作。
我尝试过使用Set-Variable -Name "SOMETHING" -Value "foo",但 PHP 没有读取。
在我的 PHP 脚本中,我只想使用 getenv('SOMETHING');。
【问题讨论】:
-
[环境]::SetEnvironmentVariable("myName", "myValue", [System.EnvironmentVariableTarget]::Machine)
-
New-Item Env:/SOMETHING -Value "foo" -
@Clijsters 您的解决方案有效!您可以将其发布为答案,我会接受。
标签: php windows powershell variables environment-variables