MakeThingsHappen
MakeThingsHappen

Reputation: 65

if condition on adb logcat doesn't work

I am trying the following code to get if condition on adb logcat:-

Search for the Exception or ANR (Activity Not Responding) on com.testapp.demo package If any Exception or ANR is found it will save the logs into the destination folder

if adb logcat | grep 'Exception*'
then
    adb logcat -d > $SILENT_EXCEPTION_FILE
fi

but I am not able to save it. Somehow this command does not work.

Upvotes: 1

Views: 333

Answers (2)

guest
guest

Reputation: 11

adb logcat outputs the logs as they arrive and never exits, so adb logcat | grep never exits either. adb logcat -d should be used if you want to read the current logs.

Upvotes: 1

mostafazh
mostafazh

Reputation: 4197

I'd suggest using the following:

adb logcat | grep --line-buffered 'Exception*' > $SILENT_EXCEPTION_FILE

Upvotes: 0

Related Questions