【发布时间】:2016-05-16 18:21:50
【问题描述】:
我已经在后台打开了一个安卓模拟器实例。我想编写一个 python 脚本,它可以使用 subprocess 模块对 logcat 中的某个单词进行 grep,并将该搜索的最新(基于时间戳)结果作为字符串返回。这该怎么做?
adb logcat | grep keyword
>> 00:00:01 keyword
>> 00:00:02 keyword
>> 00:00:03 keyword
想要返回“00:00:03关键字”行的python脚本
proc = subprocess.Popen(['adb', 'logcat', '| grep keyword'], stdout=subprocess.PIPE)
last_result=read_last_result(proc)
【问题讨论】:
-
你试过re模块吗?在 Python 官方网站上还有一个“Regular Expressions HOWTO”,您可能会觉得有帮助。
标签: python subprocess adb logcat android-logcat