title: Parse stderr inline alongside stdout using popen
body: <blockquote>
  <p><strong>What specific syntax needed to be changed in the Python3 code below in order for text output from <code>stderr</code> to be handled conditionally as it is output?</strong></p>
  </blockquote>
  <p>When the function below is run, the program is able to <code>Do something</code> whenever <code>someString</code> is found in a line of <code>stdout</code> output during runtime.</p>
  <p>The problem is that <code>stderr</code> is also printed to the command line, but <code>stderr</code> output is not handled through any string parsing code like you see below for <code>stdout</code>.</p>
  <pre><code>def runCommand(commandToRun, workingDir ):
    proc = subprocess.Popen( commandToRun,cwd=workingDir,stdout=subprocess.PIPE, shell=True)
    while True:
      line = proc.stdout.readline()
      if line:
        thetext=line.decode('utf-8').rstrip('\r|\n')
        decodedline=ansi_escape.sub('', thetext)
        print(decodedline)
        if &quot;someString&quot; in decodedline:
          print(&quot;Do something!&quot;)
      else:
        break
  </code></pre>