Grunt | Throw Compilation Error to Powershell

心不动则不痛 提交于 2019-12-11 11:40:24

问题


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.


回答1:


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" }



回答2:


Without seeing a screenshot of what is happening or more details it is hard to say what is going on here. However, the basics of PS are that you need to make sure the error is considered terminating for the catch block to trigger. Since this does not sound like a native PS cmdlet you can force it to be a terminating error like below:

Try {
$ErrorActionPreference = 'Stop'
Grunt.exe whatever
$ErrorActionPreference = 'Continue'
}
Catch {stuff}


来源:https://stackoverflow.com/questions/25443739/grunt-throw-compilation-error-to-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!