xcode 如何过滤 xcodebuild 命令行输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2244637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to filter the xcodebuild command line output?
提问by sorin
Running xcodebuild
from the console will bring you very verbose output and I wasn't able to locate any options for limit its output in order to display only warnings and errors.
xcodebuild
从控制台运行将为您带来非常详细的输出,我无法找到任何限制其输出的选项,以便仅显示警告和错误。
I'm looking for a way to capture the xcodebuild
output and filter it. It would prefer a Python solution that will work with pipes but I'm open to other approaches as long they are command line based solutions.
我正在寻找一种捕获xcodebuild
输出并对其进行过滤的方法。它更喜欢使用管道的 Python 解决方案,但我对其他方法持开放态度,只要它们是基于命令行的解决方案。
Are any tools that are already able to do this?
是否有任何工具已经能够做到这一点?
采纳答案by Guillaume
To only see the error output messages, redirect the standard output to /dev/null (a special file that works as a black hole) like this:
要仅查看错误输出消息,请将标准输出重定向到 /dev/null(用作黑洞的特殊文件),如下所示:
xcodebuild > /dev/null
If you want to capture the error output into a file, you can do:
如果要将错误输出捕获到文件中,可以执行以下操作:
xcodebuild 2> ./build_errors.log
回答by Amin Ariana
Use xcodebuild -quiet
.
使用xcodebuild -quiet
.
According to the xcodebuild man page:
根据 xcodebuild 手册页:
-quiet : Do not print any output except for warnings and errors.
-quiet :除了警告和错误外,不打印任何输出。
Bonus: No other tools necessary! (Although I also like xcodebuild | xcpretty
)
奖励:不需要其他工具!(虽然我也喜欢xcodebuild | xcpretty
)
I build with Travis CI, which complains after 4 MB of logs. This argument solved the problem.
我用 Travis CI 构建,它在 4 MB 的日志后抱怨。这个论点解决了这个问题。
回答by Koraktor
回答by rosejn
This isn't sufficient for me. Piping to /dev/null will just show you that a build failed, but you don't see the reason(s) why. Ideally we could see just the errors and/or warnings without all of the successful compiler commands.
这对我来说还不够。管道到 /dev/null 只会告诉您构建失败,但您看不到原因。理想情况下,我们可以只看到错误和/或警告,而没有所有成功的编译器命令。
This basically does the job:
这基本上完成了工作:
xcodebuild | grep -A 5 error:
回答by Thi
There's a Swift command line tool https://github.com/thii/xcbeautifythat can also format xcodebuild output.
有一个 Swift 命令行工具https://github.com/thii/xcbeautify也可以格式化 xcodebuild 输出。
回答by ravron
I love xcpretty
for looking at as a human, but I had a need to find build errors in an automated setting for propagation elsewhere, and I wanted to be sure I captured just the relevant information. The following sed command serves that purpose:
我喜欢xcpretty
像人一样看待,但我需要在其他地方传播的自动化设置中找到构建错误,我想确保我只捕获了相关信息。以下 sed 命令用于此目的:
xcodebuild | sed -nE '/error:/,/^[[:digit:]] errors? generated/ p'
Output:
输出:
main.c:16:5: error: use of undeclared identifier 'x'
x = 5;
^
main.c:17:5: error: use of undeclared identifier 'y'
y = 3;
^
2 errors generated.