3

When I run the following script, it hangs after the break, thus never executing the "do something else". I suspect that it's because after the break, adb shell logcat is still being executed. Manually pressing ctrl-c terminates logcat and allows do somethign else to execute, but is there a way to do this automatically?

adb logcat -c
adb shell logcat -s "test" | while IFS=" " read -a Array
do
    echo "${Array[2]} ${Array[3]}" 
    if [ "${Array[2]}" == "${Array[3]}" ]
    then echo "Equals"
        break
    fi
done
#do something else

Thanks

Tony
  • 1,839
  • 10
  • 27
  • 48

3 Answers3

0

The solution I ended up using was a variation of the following:

Find and kill a process in one line using bash and regex

Community
  • 1
  • 1
Tony
  • 1,839
  • 10
  • 27
  • 48
0

This is a bit old, but stumbled across this post when I was having troubles.

What I've found is happening, is when you pipe the while loop with the logcat, you're grouping the processes. Instead, you need to feed the logcat process into your while loop like so:

    adb logcat -c
    while IFS=" " read -a Array
    do
        echo "${Array[2]} ${Array[3]}" 
        if [ "${Array[2]}" == "${Array[3]}" ]
        then echo "Equals"
             break
        fi
    done < <(adb shell logcat -s "test") 

I'm probably off on my understanding, but these pages also gives a bit more background: http://mywiki.wooledge.org/ProcessSubstitution https://askubuntu.com/questions/678915/whats-the-difference-between-and-in-bash

Community
  • 1
  • 1
Kelly
  • 1
0

logcat has an option "-d": dump the log and then exit (don't block).

adb shell logcat -d -s "test"

Hope it helps.

Swing
  • 858
  • 1
  • 8
  • 21