简体   繁体   English

将python脚本输出重定向到grep

[英]Redirect python script output to grep

There is a python script that builds cocos2dx-project . 有一个Python脚本可以构建cocos2dx-project When it runs it prints out all the warning and error messages. 运行时,它会打印出所有警告和错误消息。 But I want to get only those lines that contain "error". 但是我只想获取包含“错误”的行。 Therefore, I do the following: 因此,我执行以下操作:

python ./build_native.py | grep "error"

But it still prints everything, not only "error" lines. 但是它仍然可以打印所有内容,而不仅是“错误”行。

EDIT: 编辑:

In case you need the content of the script file, you can see it here . 如果您需要脚本文件的内容,可以在此处查看

You need to redirect stderr to stdout . 您需要将stderr重定向到stdout Only then will grep filter out all lines not containing "error" 只有这样,grep才会过滤掉所有不包含“错误”的行

python ./build_native.py 2>&1 | grep "error" 

如果您只想传递错误,则可能需要尝试以下方法:

python ./build_native.py 2>&1 >/dev/null | grep "error" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM