简体   繁体   English

在bash脚本中退出adb shell logcat

[英]Exiting adb shell logcat inside a bash script

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. 我怀疑这是因为休息后,adb shell logcat仍在执行。 Manually pressing ctrl-c terminates logcat and allows do somethign else to execute, but is there a way to do this automatically? 手动按ctrl-c会终止logcat并允许执行其他操作,但是有没有办法自动执行此操作?

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 谢谢

The solution I ended up using was a variation of the following: 我最终使用的解决方案是以下内容的变体:

Find and kill a process in one line using bash and regex 使用bash和regex在一行中查找并杀死一个进程

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. 我发现正在发生的事情是,当您使用logcat传递while循环时,您正在对进程进行分组。 Instead, you need to feed the logcat process into your while loop like so: 相反,您需要像这样将logcat进程输入到while循环中:

    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 我可能不太了解,但是这些页面还提供了一些背景知识: http : //mywiki.wooledge.org/ProcessSubstitution https://askubuntu.com/questions/678915/whats-the-difference-between-扑朔迷离

logcat has an option "-d": dump the log and then exit (don't block). logcat有一个选项“ -d”:转储日志,然后退出(不阻止)。

adb shell logcat -d -s "test"

Hope it helps. 希望能帮助到你。

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

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