我正在编写一个powershell脚本,希望它能同时运行多个进程。如果任何一项工作失败,我希望它失败。所以我有一段代码,看起来像这样:
$job = Start-Job -ScriptBlock {
#do stuff
if ($LASTEXITCODE -ne 0)
{
#indicate that the job has failed.
}
}
如何指示作业失败?
要指示失败的作业,请尝试使用以下命令:
[System.Environment]::Exit(1)
这也会显示为"失败",但可能没有那么好:
Throw "the job has failed"