本文介绍了Grunt |将编译错误抛给Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的powershell脚本中调用Grunt命令。但是,如果出现任何编译失败,Grunt会将错误代码打印到控制台,但不会将任何内容返回给powershell命令行,甚至不会捕获块。

I am trying to call Grunt command from my powershell script. But in case of any complilation failure Grunt is printing the error code to the console but not returning anything to powershell command line and even not going to catch block.

请让我知道如何解决这个问题。

Please let me know how to resolve this issue.

推荐答案

诺亚的答案(使用 $ ErrorActionPreference )可以工作。或者,您可以在执行外部命令后立即使用自动变量 $?和/或 $ LastExitCode ,以便在失败时执行特定操作。例如:

Noah's answer (using $ErrorActionPreference) can work. Alternatively you can use the automatic variables $? and/or $LastExitCode immediately after executing the external command to take a specific action if it failed. This doesn't require a try-catch block For example:

Grunt.exe -whatever
if (!$?) { throw "Grunt command returned $LastExitCode" }

这篇关于Grunt |将编译错误抛给Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 21:40