我正在使用PowerShell玩耍,遇到了一个在我的电脑上可以轻松重现的崩溃。
我不确定代码是否正确。然而,运行以下代码会导致powershell.exe
和powershell_ise.exe
崩溃。我猜测我的使用if ($? = $false)
是错误的,但在这种情况下不应该发生崩溃。删除If
语句有助于避免崩溃。
我错过了什么吗?
我正在运行Windows 10 Pro和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:
$?
时,PS控制台会崩溃(版本5.1.14393.206)。 - user2226112