PowerShell是返回一个0退出代码,当发生了错误,如果调用使用-file参数。 这意味着我的版本是绿色的,当它不应该是:(
例如:
(在wtf.ps1)
$ErrorActionPreference = "Stop";
$null.split()
(CMD)
powershell -file c:\wtf.ps1
You cannot call a method on a null-valued expression.
At C:\wtf.ps1:3 char:12
+ $null.split <<<< ()
+ CategoryInfo : InvalidOperation: (split:String) [], ParentConta
insErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
echo %errorlevel%
0
powershell c:\wtf.ps1
You cannot call a method on a null-valued expression.
At C:\wtf.ps1:3 char:12
+ $null.split <<<< ()
+ CategoryInfo : InvalidOperation: (split:String) [], ParentConta
insErrorRecordException
+ FullyQualifiedErrorId : InvokeMethodOnNull
echo %errorlevel%
1
有任何想法吗?
(我试过几乎每一个想法从第2页如此: https://www.google.co.uk/search?q=powershell+file+argument+exit+code已经)