Redirect python script output to grep
Asked Answered
W

2

5

There is a python script that builds 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.

Woodard answered 30/5, 2014 at 23:57 Comment(2)
The above works perfectly fine for a script I just wrote that alternates printing "hello" and "error" 20 times. Mind giving us a sample of the output of build_native.py?Multifoliate
See my edit please. Actually it is not the direct output of the script but the compiler that script invokes. Does this change something the way pipe works?Woodard
E
12

You need to redirect stderr to stdout. Only then will grep filter out all lines not containing "error"

python ./build_native.py 2>&1 | grep "error" 
Evolve answered 31/5, 2014 at 0:17 Comment(1)
Thanks! How could I forget? That's how bad to program in windows. :(Woodard
E
0

You may want to try this, if you just want to pipe error:

python ./build_native.py 2>&1 >/dev/null | grep "error" 
Entente answered 31/5, 2014 at 0:16 Comment(3)
This will hide stdout messages.Multifoliate
Don't you want this? My assumption was that OP do not want to include error in stdout, only error in traceback.Entente
I don't presume to know what the OP wants.Multifoliate

© 2022 - 2024 — McMap. All rights reserved.