code: def _tee_output(make_proc, stdout=None, stderr=None, backend='auto'):
      
      logged_out = []
      logged_err = []
      if backend == 'auto':
          # backend = 'select' if POSIX else 'thread'
          backend = 'thread'
  
      if backend == 'select':
          if not POSIX:  # nocover
              raise NotImplementedError('select is only available on posix')
          # the select-based version is stable, but slow
          _proc_iteroutput = _proc_iteroutput_select
      elif backend == 'thread':
          # the thread version is fast, but might run into issues.
          _proc_iteroutput = _proc_iteroutput_thread
      else:
          raise ValueError('backend must be select, thread, or auto')
  
      proc = make_proc()
      for oline, eline in _proc_iteroutput(proc):
          if oline:
              if stdout:  # pragma: nobranch
                  stdout.write(oline)
                  stdout.flush()
              logged_out.append(oline)
          if eline:
              if stderr:  # pragma: nobranch
                  stderr.write(eline)
                  stderr.flush()
              logged_err.append(eline)
      return proc, logged_out, logged_err
docs: Simultaneously reports and captures stdout and stderr from a process
  
      subprocess must be created using (stdout=subprocess.PIPE,
      stderr=subprocess.PIPE)