简体   繁体   中英

how can i redirect the output of cppcheck into file?

I would like to redirect the output of cppcheck to a text file. It prints a lot of information to stdout but if I do cppcheck --enable=all --verbose . > /srv/samba/share/tmp/cppcheck.out cppcheck --enable=all --verbose . > /srv/samba/share/tmp/cppcheck.out , I do not get all the information in the file, why not?

The latest dev version of cppcheck contains a new option:

--output-file=<file name>

Add this option to direct the output into a specific file.

Usage example:

By default cppcheck prints its results to stdout:

$ cppcheck --enable=all test.cpp 
  Checking test.cpp ...
  [test.cpp:54]: (style) The scope of the variable 'middle' can be reduced.
  (information) Cppcheck cannot find all the include files (use --check-config for details)

You can use the option --output-file as follows to store the result in report.txt:

$ cppcheck --enable=all --output-file=report.txt test.cpp 
Checking test.cpp ...

Now the result is stored in report.txt:

$ more report.txt 
[test.cpp:54]: (style) The scope of the variable 'middle' can be reduced.
(information) Cppcheck cannot find all the include files (use --check-config for details)

As an alternative you could redirect the output to a file:

$ cppcheck --enable=all test.cpp 2> report.txt
Checking test.cpp ...

Now the result is stored in report.txt:

$ more report.txt 
[test.cpp:54]: (style) The scope of the variable 'middle' can be reduced.
(information) Cppcheck cannot find all the include files (use --check-config for details)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM