MCPcopy
hub / github.com/CreditTone/hooker / tail_android_file

Function tail_android_file

hooker.py:1864–1895  ·  view source on GitHub ↗

通过 adb 以 tail -f 方式实时读取安卓设备上的文件。 Ctrl + C 可安全退出。

(filepath: str)

Source from the content-addressed store, hash-verified

1862 info(result)
1863
1864def tail_android_file(filepath: str):
1865 """
1866 通过 adb 以 tail -f 方式实时读取安卓设备上的文件。
1867 Ctrl + C 可安全退出。
1868 """
1869 if not check_remote_file_exists(filepath):
1870 info("There is no log yet")
1871 return
1872 info(f"viewloging")
1873 cmd = ["adb", "shell", "tail", "-f", filepath]
1874 # 启动 adb 进程
1875 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
1876 try:
1877 for line in p.stdout:
1878 if not line:
1879 continue
1880 line = line.rstrip()
1881 if "[warn]" in line or "[WARN]" in line:
1882 info(line)
1883 elif "[error]" in line or "[ERROR]" in line:
1884 warn(line)
1885 else:
1886 print(line)
1887 except KeyboardInterrupt:
1888 print("\nCtrl + C received, stopping tail...")
1889 finally:
1890 p.terminate() # 结束 tail 进程
1891 try:
1892 p.wait(timeout=2)
1893 except subprocess.TimeoutExpired:
1894 p.kill()
1895 print("viewlog stopped.")
1896
1897class ClassNameCompleter(Completer):
1898 def __init__(self):

Callers 1

handle_commandFunction · 0.85

Calls 1

check_remote_file_existsFunction · 0.85

Tested by

no test coverage detected