-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-logcat-match-string.py
More file actions
39 lines (30 loc) · 1.1 KB
/
Copy pathTest-logcat-match-string.py
File metadata and controls
39 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import subprocess
def monitor_adb_log_for_string(target_string):
try:
# Start adb logcat process
adb_process = subprocess.Popen(
["adb", "logcat"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
bufsize=1
)
print(f"Monitoring ADB log for string: {target_string}")
# Loop to continuously read the log output
while True:
# Read a line from the log
line = adb_process.stdout.readline()
if target_string in line:
print(f"Found: {line.strip()}")
except FileNotFoundError:
print("ADB not found. Ensure it is installed and added to the system PATH.")
except KeyboardInterrupt:
print("\nScript interrupted by user. Terminating...")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Clean up: Terminate the adb process
adb_process.terminate()
if __name__ == "__main__":
target_string = "[CarInfoUpdater] update"
monitor_adb_log_for_string(target_string)