title: How to get both return code and output from subprocess in Python?
body: <p>While developing python wrapper library for Android Debug Bridge (ADB), I'm using <em>subprocess</em> to execute adb commands in shell. Here is the simplified example:</p>
  
  <pre><code>import subprocess
  
  ...
  
  def exec_adb_command(adb_command):
      return = subprocess.call(adb_command)
  </code></pre>
  
  <p>If command executed propery <em>exec_adb_command</em> returns 0 which is OK.</p>
  
  <p>But some adb commands return not only "0" or "1" but also generate some output  which I want to catch also. <em>adb devices</em> for example:</p>
  
  <pre><code>D:\git\adb-lib\test&gt;adb devices
  List of devices attached
  07eeb4bb        device
  </code></pre>
  
  <p>I've already tried <em>subprocess.check_output()</em> for that purpose, and it does return output but not the return code ("0" or "1").</p>
  
  <p>Ideally I would want to get a tuple where t[0] is return code and t[1] is actual output.</p>
  
  <p>Am I missing something in subprocess module which already allows to get such kind of results?</p>
  
  <p>Thanks!</p>