Python 如何获取adb命令的输出并输入变量
我的问题在于以下代码:Python 如何获取adb命令的输出并输入变量,python,adb,Python,Adb,我的问题在于以下代码: import subprocess as sp import os # CONSTANTS SRL = 'serial_code' SCF = 'scaling_cur_freq' SMF = 'scaling_max_freq' SAV = 'scaling_available_frequencies' ROOT = 'adb -s {} root' SHL = 'adb shell ' CD = '/sys/devices/system/cpu/cpu0/cpufr
import subprocess as sp
import os
# CONSTANTS
SRL = 'serial_code'
SCF = 'scaling_cur_freq'
SMF = 'scaling_max_freq'
SAV = 'scaling_available_frequencies'
ROOT = 'adb -s {} root'
SHL = 'adb shell '
CD = '/sys/devices/system/cpu/cpu0/cpufreq/'
CAT = '"cat" '
os.system(ROOT.format(SRL))
print("Available Frequencies:")
os.system(SHL+CAT+CD+SAV) # 1
print("Initial Frequency:")
os.system(SHL+CAT+CD+SCF) # 2
x = sp.check_output(os.system(SHL+CAT+CD+SAV)) # The problem
print(x)
我想把#1行return放在var x中,但我得到的是:
> adbd is already running as root
> Available Frequencies:
> 614400 883200 1036800 1363200 1536000 1670400 1804800
> Initial Frequency:
> 1363200
>Traceback (most recent call last):
File "/home/jvff/CpuFreq/CpuFreq.py", line 19, in <module>
x = sp.check_output(os.system(SHL + CAT + CD + SAV)) # The problem
File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.8/subprocess.py", line 489, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.8/subprocess.py", line 1567, in _execute_child
args = list(args)
TypeError: 'int' object is not iterable
> 614400 883200 1036800 1363200 1536000 1670400 1804800
> Process finished with exit code 1
adbd已作为root用户运行
>可用频率:
> 614400 883200 1036800 1363200 1536000 1670400 1804800
>初始频率:
> 1363200
>回溯(最近一次呼叫最后一次):
文件“/home/jvff/CpuFreq/CpuFreq.py”,第19行,在
x=sp.检查输出(操作系统(SHL+CAT+CD+SAV))#问题
检查输出中的文件“/usr/lib/python3.8/subprocess.py”,第411行
返回运行(*popenargs,stdout=PIPE,timeout=timeout,check=True,
文件“/usr/lib/python3.8/subprocess.py”,第489行,正在运行
使用Popen(*popenargs,**kwargs)作为流程:
文件“/usr/lib/python3.8/subprocess.py”,第854行,在__
self.\u execute\u child(参数、可执行文件、预执行文件、关闭文件、,
文件“/usr/lib/python3.8/subprocess.py”,第1567行,在执行子进程中
args=列表(args)
TypeError:“int”对象不可编辑
> 614400 883200 1036800 1363200 1536000 1670400 1804800
>进程已完成,退出代码为1
我需要知道如何捕捉命令#1的返回和#2的返回,并输入一个变量,如x,y。。。
基本上,在这种情况下,我想要X=614400883200 1036800 13632001536000 1670400 1804800
提前谢谢!!!我找到了答案
多亏了克里斯·邦奇
x=os.popen(SHL+CAT+CD+SAV).read()