gpt4 book ai didi

javascript - 如何在 PowerShell 中捕获闭包编译器输出?

转载 作者:行者123 更新时间:2023-11-29 10:52:04 26 4
gpt4 key购买 nike

我在 PowerShell 命令行中输入:

java -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js

它会生成此错误输出:

temp1.js:359: WARNING - Suspicious code. The result of the 'getprop' operator is not being used.
$acms.x
^

0 error(s), 1 warning(s)

(我确切地知道 JavaScript 出了什么问题:这不是这里的问题。)

我想捕获这个错误输出。但是,如果我尝试:

$errs = java -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js

$errs 最终为空。但是如果我尝试:

java -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js 2>errs.txt

errs.txt 捕获了这个:

java.exe : temp1.js:359: WARNING - Suspicious code. The result of the 'getprop' operator is not being used.
At line:1 char:5
+ java <<<< -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js 2>errs.txt
+ CategoryInfo : NotSpecified: (temp1.js:359: W...not being used.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

$acms.x
^



0
error(s),
1
warning(s)

很明显,闭包编译器的错误输出与 PowerShell 错误输出交织在一起。

有没有办法只捕获闭包编译器输出?

最佳答案

如果你正在做:

$errs = command 2>&1

$errs.Exception 会给你消息。

如果只发生错误(并且只有一个),$errs 将有一个 ErrorRecord,您将能够执行上述操作并获得您想要的错误。

否则,它将是错误记录和/或正常输出的数组。

所以你将不得不做

$errs | ?{$_.GetType().Name -eq "ErrorRecord"} |选择-展开异常

关于javascript - 如何在 PowerShell 中捕获闭包编译器输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8271293/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com