Terminate the "logcat" process started by my application using Python
I have created one small application having a button tapping on which will start the "adb logcat" process, but after starting this process we have to give Ctrl+C command to stop it. I want to make it generic so don't want to use Ctrl+C command and want to terminate it itself after few seconds (say 5 secs).
code that start executing on tapping the button is:
def LOGGER():
buildID=os.popen("adb shell getprop ro.build.id").read().strip()
device=os.popen("adb shell getprop ro.product.device").read().strip()
Log = ("D:\\Profiles\\hjv743\\Desktop\\Logs\\"+device+"_"+buildID)
if not os.path.isdir(Log):
os.mkdir(Log)
os.system("adb pull /data/logger "+Log+"\\flash")
os.system("adb pull /sdcard-ext/logger "+Log+"\\sdcard-ext")
I have tried killing the process using its pid but it does not terminate it and it continues to run in background 开发者_运维知识库(Needless to mention the process name is always "logcat" as the process is adb logcat)
Also during this complete process my application kept hung as the process is running, so I cannot have another button (using Tkinter) tapping on which will terminate the running process. So the only option left with me is to terminate it automatically after some time. This is very important for my applications as I cannot interact with it during the whole process.
Am I doing this wrong way and there any other way of doing the same process. Can I start the (adb logcat) process as a process in background and introduce one more button which will fetch the pid and will terminate it manually.
Any help is appreciated.
You can use the '-d' flag, if you do not want to run the process infinitely. As in "adb logcat -d". This way you don't need to bother about killing the process. :)
import os,sys
os.system("adb logcat -d | grep -i --line-buffered searchstring > logtest.txt")
--line-buffered -> for coping consol output to logtest.txt
-d -> prevent logcat process from waiting for infinite time
精彩评论