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

标签 linux bash redirect stdout cppcheck

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

最佳答案

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)

关于linux - 如何将 cppcheck 的输出重定向到文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44420138/

相关文章:

linux - ffmpeg 修复水印大小或百分比

linux - 通过 aws cli 从 codecommit 存储库中提取带有扩展名的文件名

linux - 为什么 fork() 不立即给出正确的 pid?

javascript - 移动重定向不起作用

redirect - Scalatra - 我们如何进行内部重定向/转发请求

php - 包含带有 .htaccess 的子文件夹

c - 解析两个 XML 标签之间的值

c - 实现系统调用而不显式调用它们

linux - 在 Windows 中利用 Unix 命令的强大功能

c - 如何在 C 脚本中分配从命令行传递的文件名?