0

my problem is in this code:

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)

I want to put the #1 line return in the var x but, instead, i get this:

> 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

I need to know how can I catch the return of the command # 1 and the return of # 2 and put in a variable like x,y... Basically, i want X = 614400 883200 1036800 1363200 1536000 1670400 1804800 in this case

Thanks in advance!!!

1 Answers1

0

i find the answer Assign output of os.system to a variable and prevent it from being displayed on the screen

Thanks to Chris Bunch!

x = os.popen(SHL + CAT + CD + SAV).read()