要使用Python和ADB命令查看日志,您可以使用subprocess
模块来执行ADB命令并将输出捕获到Python中
import subprocess def get_adb_log(): try: # 执行ADB logcat命令并将输出捕获到Python中 output = subprocess.check_output(["adb", "logcat"], stderr=subprocess.STDOUT, text=True) # 打印捕获的日志 print(output) except subprocess.CalledProcessError as e: print(f"Error occurred while executing ADB logcat command: {e}") if __name__ == "__main__": get_adb_log()
这个脚本将执行adb logcat
命令并将日志输出到Python中。请注意,您需要确保已经安装了ADB工具并将其添加到了系统路径中。