提问人:Charles Anderson 提问时间:11/25/2011 更新时间:11/26/2011 访问量:790
如何在 PowerShell 中捕获闭包编译器输出?
How to capture closure compiler output in PowerShell?
问:
我在 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 错误输出交错。
有没有办法只捕获闭包编译器的输出?
答:
3赞
manojlds
11/26/2011
#1
如果你正在做:
$errs = command 2>&1
$errs.Exception
会给你消息。
如果只发生错误(并且只有一个),$errs将有一个,您将能够执行上述操作并获得所需的错误。ErrorRecord
否则,它将是错误记录和/或正常输出的数组。
所以你将不得不做
$errs | ?{$_.GetType().Name -eq "ErrorRecord"} | select -expand exception
评论
0赞
Charles Anderson
11/28/2011
这是两者中的第二个。谢谢。
评论