我正在玩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"
}
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud) powershell ×1