Running Closure Compiler to get warning messages

388 views Asked by At

I'm using Closure Compiler running on my local machine to generate client files. I'm also using the online closure tool at http://closure-compiler.appspot.com/home to check my work: I paste my JavaScript code, press compile and if there's a warning the compiler shows me the warnings with the actual lines and line numbers.

I'm wondering if it's possible to get the same output using the local version of Closure Compiler. This is the code I use to compile the files and get the compiled JavaScript but this time, I want the warnings:

System.IO.File.WriteAllText(FileNameInput, TheJS);

string JavaArgument = "-jar ClosureCompiler/compiler.jar --js ClosureCompiler/initial" + FileNameSuffix + ".js --js_output_file ClosureCompiler/compiled" + FileNameSuffix + ".js --compilation_level ADVANCED_OPTIMIZATIONS --externs ExternalFiles/JqueryExtern.js";

System.Diagnostics.Process clientProcess = new System.Diagnostics.Process();

clientProcess.StartInfo.FileName = "java.exe";
clientProcess.StartInfo.Arguments = JavaArgument;
clientProcess.StartInfo.CreateNoWindow = true;
clientProcess.StartInfo.UseShellExecute = false;
clientProcess.StartInfo.WorkingDirectory = HttpRuntime.AppDomainAppPath;

clientProcess.Start();
clientProcess.WaitForExit();

string TheOutputScript = System.IO.File.ReadAllText(FileNameOutput);

What do I need to change?

2

There are 2 answers

3
Chad Killingsworth On BEST ANSWER

The compiler writes the warnings and errors to standard error which isn't going to show in your output file.

Option 1 - Redirect Standard Error to a File

Add 2> errorfile.txt to the end of your execution command to redirect standard error to a file. You'll then need to read that file.

Option 2 - Read the Standard Error Property of the Process

This should be as simple as:

clientProcess.StandardError
0
frenchie On

Chad's answer was great in that in pointed me towards the code. For those who need the actual code, this is what I have:

clientProcess.StartInfo.FileName = "java.exe";
clientProcess.StartInfo.Arguments = JavaArgument;
clientProcess.StartInfo.CreateNoWindow = true;
clientProcess.StartInfo.UseShellExecute = false;
clientProcess.StartInfo.WorkingDirectory = HttpRuntime.AppDomainAppPath;
clientProcess.StartInfo.RedirectStandardError = true; //add this line

clientProcess.Start();
string CompilerErrors = clientProcess.StandardError.ReadToEnd(); //add this line
clientProcess.WaitForExit();

return System.IO.File.ReadAllText(FileNameOutput); //add breakpoint here

Now all you have to do is add a break point at the end and watch the variable CompilerErrors.