Python调用adb shell ls,取前5个字符存放,并打印出来
import subprocess def run_adb_shell_command(command):# 设置adb的路径,根据您的实际情况进行修改 adb_path = 'adb' # 使用subprocess运行adb shell命令,并捕获输出 result = subprocess.run([adb_path, 'shell', command], capture_output=True, text=True) # 检查命令是否成功执行 if result.returncode != 0: print(f"Error executing command: {result.stderr}") return Noneprint('Stdout:', result.stdout)return resultdef run_adb_shell_command_and_get_first_chars(command, num_start, num_chars): result = run_adb_shell_command(command)# 获取命令输出,并取前num_chars个字符 output = result.stdout.strip()[num_start:num_start + num_chars] # 打印前num_chars个字符 #print(f"First {num_chars} characters of the output: {output}") return outputdef concatenate_strings(str1, str2): #print(str1 + str2)return str1 + str2MY_CONSTANT = 42 first_five_chars = int(run_adb_shell_command_and_get_first_chars('expr 2 + 3', 0, 1))run_adb_shell_command(concatenate_strings('expr 2 + ', str(MY_CONSTANT + first_five_chars)))#print(first_five_chars)