import subprocess,re
def run_cmd(cmd):
p=subprocess.Popen(cmd,stdout=subprocess.PIPE,stdin=subprocess.PIPE,stderr=subprocess.PIPE,shell=False)
stdout,stderr=p.communicate()
p.wait
if stdout:
return_code=stdout.decode()
elif stderr:
return_code=stderr.decode()
return_code=re.sub(r'\x1b\[[0-9;]*m|\r', '', return_code)
return return_code
print(run_cmd('adb root'))