gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 01:20:49 27 4
gpt4 key购买 nike

我想将 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com