gpt4 book ai didi

powershell - Powershell:将环境变量设置为两倍

转载 作者:行者123 更新时间:2023-12-03 00:06:52 24 4
gpt4 key购买 nike

下面的代码试图更改环境变量PATH,但不幸的是,字符串被加倍了:

Blockquote C:\Windows;C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\; C:\Windows;C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\; C:\Users\Arthur\AppData\Local\Programs\Microsoft VS Code\bin;;C:\LJ\jdk-13\bin Blockquote



'; C:\ LJ \ jdk-13 \ bin'是我要添加的唯一字符串

您知道错误在哪里吗?
谢谢
    $zip =  [io.compression.zipfile]::OpenRead($jdkDownloadPathName).Entries
$jdkFolder = (($zip | Where-Object FullName -match '/' | Select-Object -First 1).Fullname -Split '/')[0]
$jdkInstallFolder ="$($installJavaAntPath)\$($jdkFolder)"
$PATH = $env:Path
$PATH += ";" + $jdkInstallFolder +"\bin"
Set-EnvironmentVariable -name PATH -Value $PATH -Target User
Set-EnvironmentVariable -name JAVA_HOME -Value $jdkInstallFolder -Target User
    function Set-EnvironmentVariable
{
param
(
[Parameter(Mandatory=$true)]
[String]
$Name,

[Parameter(Mandatory=$true)]
[String]
$Value,

[Parameter(Mandatory=$true)]
[EnvironmentVariableTarget]
$Target
)
[System.Environment]::SetEnvironmentVariable($Name, $Value, $Target)
}

最佳答案

$PATH = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::User)
$PATH += ";" + $jdkInstallFolder +"\bin"
[System.Environment]::SetEnvironmentVariable('PATH',$PATH, [System.EnvironmentVariableTarget]::User)

我了解了,谢谢@Lee_Dailey!

关于powershell - Powershell:将环境变量设置为两倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59551839/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com