I am typing this at the PowerShell command line:
java -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js
and it generates this error output:
temp1.js:359: WARNING - Suspicious code. The result of the 'getprop' operator is not being used.
$acms.x
^
0 error(s), 1 warning(s)
(I know exactly what’s wrong with the JavaScript: that’s not the issue here.)
I want to capture this error output. However, if I try:
$errs = java -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js
$errs ends up empty. But then if I try:
java -jar closure-compiler.jar --js temp1.js --js_output_file temp2.js 2>errs.txt
errs.txt captures this:
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)
Clearly the error output from the closure compiler is getting interleaved with PowerShell error output.
Is there any way to just capture the closure compiler output?
If you are doing:
$errs.Exceptionwill give you the message.If only the error ( and only one) occured, $errs will have an
ErrorRecordand you will be able to do the above and get the error that you want.Otherwise, it will be an array of errorrecords and / or normal output.
So you will have to do
$errs | ?{$_.GetType().Name -eq "ErrorRecord"} | select -expand exception