gpt4 book ai didi

PowerShell 在 `if ( $? = $false )` 上崩溃

转载 作者:行者123 更新时间:2023-12-04 22:57:04 24 4
gpt4 key购买 nike

我正在使用 PowerShell,但遇到了可以在我的计算机上轻松重现的崩溃。

我不确定代码是否正确。但是,运行以下代码会使 powershell.exepowershell_ise.exe碰撞。我猜我使用了 if ( $? = $false )是错误的,但在这种情况下不应该发生崩溃。删除 If声明有助于避免崩溃。

有什么我想念的吗?

我正在运行 Windows 10 专业版和 PowerShell 5.1.14393.206。

更新 1

好的,感谢@Martin 我知道我错误地使用了 =而不是 -eq .但是为什么会发生这种崩溃?

更新 2

向 PowerShell UserVoice 提交错误报告:https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/16977433-assigning-a-value-to-false-crashes

更新 3

这似乎是一个已知的错误:https://github.com/PowerShell/PowerShell/issues/2243应该很快修复 https://github.com/PowerShell/PowerShell/pull/2320

Test-Path "C:\test"
if ( $? = $false ) {
Out-Host "Hello World"
}

Fault bucket 127386360339, type 5
Event Name: PowerShell
Response: Not available
Cab Id: 0

Problem signature:
P1: powershell.exe
P2: 10.0.14393.206
P3: stem.Management.Automation.PSInvalidCast
P4: stem.Management.Automation.PSInvalidCast
P5: ation.LanguagePrimitives.ThrowInvalidCastException
P6: ation.LanguagePrimitives.ThrowInvalidCastException
P7: Pipeli..ution Thread
P8:
P9:
P10:

最佳答案

你的代码是错误的。您是 assigning $falsequestion mark variable这是一个只读变量。您可能想要替换 = -eq :

Test-Path "C:\test"
if ( $? -eq $false ) {
Out-Host "Hello World"
}

关于PowerShell 在 `if ( $? = $false )` 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40448706/

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