Question

I would like to run CppCheck on our code as part of our build. However, I cannot make it save the output to a file if not executed from a command prompt.

From a regular (windows) command prompt, or with hard coded paths inside a .bat file the following works fine:

"C:\Program Files\Cppcheck\CppCheck.exe" --enable=all  --xml-version=2 "<full_path_with_spaces_to_source>" 2> cppcheck_result.xml

However, I would like to run it from a script, e.g. Powershell. I tried this:

& 'C:\Program Files (x86)\Cppcheck\cppcheck.exe' --enable=all --xml-version=2 $CheckPath | Out-File cppcheck_ps.xml

But this pipes the files checked into the xml file and the xml results are shown in the output pane of Powershell.

I also tried running the exe file directly from our build server (TeamCity) as a command line build step, but no output file is created! The check is performed and the normal output is seen in the build log, but somehow the 2> is lost. I am using TeamCity version 7.1.1.

I have searched everywhere I could think of, and the closest I could find was This.

But this did not work for me, so any help would be greatly appreciated.

Alternatively, if you know of a better way to run CppCheck and get the results, please let me know.

Was it helpful?

Solution

I don't have this tool but if you need to capture stderr from it try:

& '.\cppcheck.exe' --enable=all --xml-version=2 $CheckPath 2>&1 | Out-File cppcheck_ps.xml

Note I removed the full path to the exe only to shorten the command for display.

OTHER TIPS

I don't know anything about how powershell works. But if you have to use 2>&1 instead of just 2> then you'll of course get the stdout messages too. But you could use the cppcheck flag --quiet or -q to skip stdout output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top