Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception PowerShell能否将错误输出自动转换为异常?_Exception_Powershell - Fatal编程技术网

Exception PowerShell能否将错误输出自动转换为异常?

Exception PowerShell能否将错误输出自动转换为异常?,exception,powershell,Exception,Powershell,在我的PowerShell脚本中,我调用了一些命令行工具(不是cmdlet),这些工具可能会输出错误文本,并在错误条件下将errorlevel设置为非零。我希望这些工具中的任何错误都能中止我的脚本 最好的方法是什么 有没有办法让PowerShell自动检查$?和stderr在每个命令之后抛出异常?我一直在想4NT或VBScript所具有的“出错”特性——一个全局手表。不是很面向对象,所以我希望PowerShell有更好的 [编辑:最后两个问题移至。]您需要编写一个函数来完成此操作,或者在脚本中不

在我的PowerShell脚本中,我调用了一些命令行工具(不是cmdlet),这些工具可能会输出错误文本,并在错误条件下将errorlevel设置为非零。我希望这些工具中的任何错误都能中止我的脚本

最好的方法是什么

有没有办法让PowerShell自动检查$?和stderr在每个命令之后抛出异常?我一直在想4NT或VBScript所具有的“出错”特性——一个全局手表。不是很面向对象,所以我希望PowerShell有更好的


[编辑:最后两个问题移至。]

您需要编写一个函数来完成此操作,或者在脚本中不断检查错误级别

有关执行此操作的函数的一些信息,请访问:


其他有用的信息可以在上找到。

Scott,我想把最后两个问题单独列为一个问题。