title: Trouble calling bash from within python
body: <p>I am trying to use python to help do some automation around an incremental build function in the Android build system.  Generally, from a given directory, I would execute the following command to build whatever is in that directory and subdirectories:</p>
  
  <pre><code>mm -j8
  </code></pre>
  
  <p>This is analogous to a "make" command, only it is incremental build and is defined as a function in a bash file called envsetup.sh.  What is does it not important, just know that it's a function defined in a bash script somewhere in the file system.  To execute this, I can also do:</p>
  
  <pre><code>bash -c ". /path/to/envsetup.sh; mm -j8"
  </code></pre>
  
  <p>This method of calling it will be important in calling the function from python.  I have followed the solution <a href="https://stackoverflow.com/a/5826523/343381">here</a> which shows how to call a function within a bash script from python.  I have used this method in a simple script that, in theory, should just spit out the STDOUT and STDERR from executing the command:</p>
  
  <pre><code>import subprocess
  
  command = ['bash', '-c', '. /path/to/envsetup.sh; mm -j8']
  (stdout, stderr) = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()
  
  print 'stdout: ' + stdout
  print 'stderr: ' + stderr
  </code></pre>
  
  <p>The call to <code>Popen</code>, however, never returns.  What am I doing wrong that would allow bash to execute the command properly, but Python hangs when executing the command?</p>