我正在玩PowerShell,並且遇到了一個崩潰,我可以在計算機上輕鬆地重現。
我不確定代碼是否正確。但是,運行以下片段使得powershell.exe
和powershell_ise.exe
崩潰。我想我的使用if ($? = $false)
是錯誤的,但崩潰不應該發生在這種情況下。刪除If
聲明有助於避免崩潰。
有什麼我失蹤?
我正在運行Windows 10 Pro和PowerShell 5.1.14393.206。
更新1
OK,感謝@馬丁,我知道我錯誤地使用=
代替-eq
。但爲什麼會發生這種事故?
更新2
提交一個bug報告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) – Swonkie
而且它似乎沒有發生在v5.0(至少v5.0.10586.122)。顯示有關將值分配給只讀變量的正確錯誤消息。 – sodawillow
@Swonkie請點擊https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/16977433-assigning-a-value-to-false-crashes上的投票我已經提交了一個錯誤報告和您的投票up可以幫助。 :) – bahrep