如何将cppcheck的输出重定向到文件?

10

我想将cppcheck的输出重定向到文本文件。它会向stdout打印大量信息,但如果我运行cppcheck --enable=all --verbose . > /srv/samba/share/tmp/cppcheck.out,我在文件中没有得到所有信息。为什么?如何才能将结果保存到文件中?


4
你可能也希望重定向标准错误输出,因此尝试将>替换为>& - Basile Starynkevitch
1个回答

11

最新的 cppcheck 开发版本添加了一个新选项:

--output-file=<file name>

添加此选项可将输出定向到特定文件。

用法示例:

默认情况下,cppcheck将其结果打印到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)

您可以使用以下选项--output-file将结果存储在report.txt中:
$ cppcheck --enable=all --output-file=report.txt test.cpp 
Checking test.cpp ...

现在结果存储在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)

作为替代方案,您可以将输出重定向到文件:

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

现在结果存储在 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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接