I've been looking for a way to terminate a PowerShell (PS1) script when an unrecoverable error occurs within a function.
(我一直在寻找一种在函数内发生不可恢复的错误时终止PowerShell(PS1)脚本的方法。)
For example: (例如:)
function foo() {
# Do stuff that causes an error
$host.Exit()
}
Of course there's no such thing as $host.Exit()
.
(当然没有$host.Exit()
这样的东西。)
There is $host.SetShouldExit()
, but this actually closes the console window, which is not what I want. (有$host.SetShouldExit()
,但这实际上关闭了控制台窗口,这不是我想要的。)
What I need is something equivalent to Python's sys.exit()
that will simply stop execution of the current script without further adieu. (我需要的是与Python的sys.exit()
相当的东西,它将简单地停止执行当前脚本而不需要进一步的操作。)
Edit: Yeah, it's just exit
.
(编辑:是的,它只是exit
。)
Duh. (咄。)
ask by kprobst translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…