docs: def run(
      cmd,
      shell=False,
      cwd=None,
      log_in_real_time=True,
      check_returncode=True,
      callback=None,
  ):
      """ Run 'cmd' in a shell and return the combined contents of stdout and
      stderr (Blocking).  Throws an exception if the command exits non-zero.
  
      :param cmd: list of str (or single str, if shell==True) indicating
         the command to run
      :param shell: boolean indicating whether we are using advanced shell
          features. Use only when absolutely necessary, since this allows a lot
          more freedom which could be exploited by malicious code. See the
          warning here:
          http://docs.python.org/library/subprocess.html#popen-constructor
      :param cwd: dir command is run from.
      :type cwd: str
      :param log_in_real_time: boolean indicating whether to read stdout from the
          subprocess in real time instead of when the process finishes.
      :param check_returncode: Indicate whether a :exc:`~exc.CommandError`
          should be raised if return code is different from 0.
      :type check_returncode: :class:`bool`
      :param cwd: dir command is run from, defaults :attr:`~.path`.
      :type cwd: str
      :param callback: callback to return output as a command executes, accepts
          a function signature of ``(output, timestamp)``. Example usage::
  
              def progress_cb(output, timestamp):
                  sys.stdout.write(output)
                  sys.stdout.flush()
              run(['git', 'pull'], callback=progrses_cb)
      :type callback: func
      """
      proc = subprocess.Popen(
          cmd,
          shell=shell,
          stderr=subprocess.PIPE,
          stdout=subprocess.PIPE,
          creationflags=0,
          bufsize=1,
          cwd=cwd,
      )
  
      all_output = []
      code = None
      line = None
      while code is None:
          code = proc.poll()
  
          # output = console_to_str(proc.stdout.readline())
          # all_output.append(output)
          if callback and callable(callback):
              line = console_to_str(proc.stderr.read(128))
              if line:
                  callback(output=line, timestamp=datetime.datetime.now())
      if callback and callable(callback):
          callback(output='\r', timestamp=datetime.datetime.now())
  
      lines = filter(None, (line.strip() for line in proc.stdout.readlines()))
      all_output = console_to_str(b'\n'.join(lines))
      if code:
          stderr_lines = filter(None, (line.strip() for line in proc.stderr.readlines()))
          all_output = console_to_str(b''.join(stderr_lines))
      output = ''.join(all_output)
      if code != 0 and check_returncode:
          raise exc.CommandError(output=output, returncode=code, cmd=cmd)
      return output