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.
I don't have this tool but if you need to capture stderr from it try:
Note I removed the full path to the exe only to shorten the command for display.