android - 退出 adb logcat 的 Bash 脚本
问题描述
我正在尝试编写一个脚本来启动应用程序并检查 logcat 中的字符串。一旦我找到字符串。我想退出 logcat 并杀死应用程序
if adb shell monkey -p com.app.dev -c android.intent.category.LAUNCHER 1 | adb logcat | grep --line-buffered 'match_text'
then
adb shell am force-stop com.app.dev
fi
我的脚本看起来像上面那样。但是在我在 logcat 中找到匹配的行之后,由于 logcat 已经接管了 bash 命令进程,因此其中的代码永远不会执行。
解决方案
你应该做这样的事情
mkfifo temp
# start you app here, I would use am
adb shell monkey -p com.app.dev -c android.intent.category.LAUNCHER 1
adb logcat > temp &
pid=$!
if grep -qm1 --line-buffered 'match_text' < temp
then
kill $pid
rm temp
adb shell am force-stop com.app.dev
fi
推荐阅读
- sql - JPQL,通过主键获取JoinTable中定义的所有ManyToMany关系
- excel - 使用 Excel VBA 选择 Word Doc
- graphql - GraphQL:获取特定实现的孩子
- excel - 获取简单 Range.Copy 行的“下标超出范围”错误。我究竟做错了什么?
- javascript - 在 C# 中调用 Javascript 函数
- node.js - NodeJS 依赖中的环境变量
- ehcache - 你能遍历 org.ehcache.CacheManager 管理的缓存吗?
- python - 如何在 Slack webClient 中更改 file_upload 格式
- java - java.lang.IllegalStateException:这个消费者已经被关闭
- react-native - 如何正确重用 useEffect 挂钩