title: Constantly print Subprocess output while process is running
body: <p>To launch programs from my Python-scripts, I'm using the following method:</p>
  <pre><code>def execute(command):
      process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
      output = process.communicate()[0]
      exitCode = process.returncode
  
      if (exitCode == 0):
          return output
      else:
          raise ProcessException(command, exitCode, output)
  </code></pre>
  <p>So when i launch a process like <code>Process.execute(&quot;mvn clean install&quot;)</code>, my program waits until the process is finished, and only then i get the complete output of my program. This is annoying if i'm running a process that takes a while to finish.</p>
  <p>Can I let my program write the process output line by line, by polling the process output before it finishes in a loop or something?</p>
  <p>I found <a href="https://stackoverflow.com/questions/984941/python-subprocess-popen-from-a-thread">this</a> article which might be related.</p>