【问题标题】:how can i redirect the output of cppcheck into file?如何将 cppcheck 的输出重定向到文件中?
【发布时间】:2017-11-09 05:58:32
【问题描述】:

我想将 cppcheck 的输出重定向到一个文本文件。它会向stdout 打印很多信息,但如果我打印cppcheck --enable=all --verbose . > /srv/samba/share/tmp/cppcheck.out,我不会得到文件中的所有信息,为什么不呢?

【问题讨论】:

  • 您可能还想重定向stderr,因此请尝试将> 替换为>&

标签: linux bash redirect stdout cppcheck


【解决方案1】:

cppcheck 的最新开发版包含一个新选项:

--output-file=<file name>

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

使用示例:

默认情况下,cppcheck 将其结果打印到标准输出:

$ 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)

【讨论】:

    猜你喜欢
    • 2017-04-04
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2012-06-26
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多