from subprocess import Popen, PIPE, STDOUT
out = Popen(['adb', 'devices'], stderr=STDOUT, stdout=PIPE)
t = out.communicate()[0], out.returncode
print(t)
'List of devices attached \n\n', 0
How to get both return code and output from subprocess in Python?