我正在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错误输出混杂在一起。
有没有办法只捕获闭包编译器的输出?