I'm creating a little Application where I can insert the IP-address of my android phone, and then with one button press. I am wirelessly connected over ADB. This works, now I want to display the log of adb logcat
in a scrollable, not editable textfield. But here I bump into a problem, I am trying to catch the output of the logcat command like this p = os.popen("adb logcat")
and then printing it like so print(p.read())
. This only makes my application (tkinter) freeze, I am guessing this has to do with the fact that the printing never end. Does anybody have an idea on how to display the logcat result.
Code of function
def logcatcommand():
p = os.popen("adb logcat")
print(p.read())
Button:
button2 = tk.Button(text="Open logcat",width=25, height=3, command=logcatcommand)
button2.grid(row=5, column=0)
Do you guys also have an idea on how I could display this information realtime? I think I have to use code like this:
result = scrolledtext.ScrolledText(window, wrap = tk.WORD, width = 40, height = 10, font = ("Times New Roman", 15))
result.grid(column = 1, row=0)
result.insert(tk.INSERT, output)
result.configure(state ='disabled')
where output is the realtime data retrieved from the terminal.
sample lines logcat:
09-10 14:10:28.479 971 3009 I WifiHAL : event received NL80211_CMD_VENDOR, vendor_id = 0x1374, subcmd = 0xd
09-10 14:10:34.779 1526 4567 I BatteryStatsService: In wakeup_callback: resumed from suspend
09-10 14:10:35.321 1526 4567 I BatteryStatsService: In wakeup_callback: suspend aborted
Edit: Thanks to Javier Gonzalez I was able to print the logcat using:
def logcatcommand():
popen = subprocess.Popen(args="adb logcat", shell=True, stdout=subprocess.PIPE)
return iter(popen.stdout.readline, b"")
def logcatresult():
for line in logcatcommand():
print(line)
But when trying to set the value into a variable or just generally doing anything else (like try to press another button), the only thing I will see is the rainbow spinning wheel from Mac OSX.
Greetz