【发布时间】:2012-05-16 14:17:24
【问题描述】:
如果使用 -File 参数调用,当发生错误时,Powershell 将返回 0 退出代码。这意味着我的构建不应该是绿色的:(
例如:
(在 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
有什么想法吗?
(我已经尝试了前两页的所有想法:https://www.google.co.uk/search?q=powershell+file+argument+exit+code)
【问题讨论】:
标签: powershell exit-code