title: Taking a section of subprocess output on each line using regex and sending it real-time
body: <p>I wrote this function to take the <code>subprocess</code> output line-by-line, which then <code>yield</code>s each line and sends it to the user.</p>
  <pre class="lang-py prettyprint-override"><code>def invoke_process_popen_poll_live(command, shellType=False, stdoutType=subprocess.PIPE):
      &quot;&quot;&quot;runs subprocess with Popen/poll so that live stdout is shown&quot;&quot;&quot;
      try:
          process = subprocess.Popen(command, shell=shellType, stdout=stdoutType, universal_newlines=True)
      except:
          print(&quot;ERROR {} while running {}&quot;.format(sys.exc_info()[1], command))
          return None
      while True:
          output = process.stdout.readline()
          yield output.strip()
          if process.poll() is not None:
              break
          if output:
              output.strip()
      rc = process.poll()
      return rc
  </code></pre>
  <p>The output is the <code>youtube-dl</code> download stats which is like this:</p>
  <pre class="lang-none prettyprint-override"><code>[youtube] knge_1uWbro: Downloading webpage
  [download] Destination: ./DLVids/Kitty_says_Uh-Oh_very_clearly-knge_1uWbro-720.f398.mp4
  
  [download]   0.1% of 963.52KiB at  3.82KiB/s ETA 04:11
  [download]   0.3% of 963.52KiB at 11.46KiB/s ETA 01:23
  [download]   0.7% of 963.52KiB at 26.61KiB/s ETA 00:35\n
  .
  .
  .
  </code></pre>
  <p>Is there any way to take each line's output like this:</p>
  <pre class="lang-none prettyprint-override"><code>0.1% of 963.52KiB at  3.82KiB/s
  0.3% of 963.52KiB at 11.46KiB/s
  0.7% of 963.52KiB at 26.61KiB/s
  </code></pre>