如果使用 -File 参数调用,当发生错误时,Powershell 将返回 0 退出代码。这意味着我的构建不应该是绿色的:(
例如:
(在 wtf.ps1 中)
$ErrorActionPreference = "Stop";
$null.split()
(命令)
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
有任何想法吗?
(我已经尝试了前两页的所有想法:https ://www.google.co.uk/search?q=powershell+file+argument+exit+ code)