def run(<EOL>cmd,<EOL>shell=False,<EOL>cwd=None,<EOL>log_in_real_time=True,<EOL>check_returncode=True,<EOL>callback=None,<EOL>):
proc = subprocess.Popen(<EOL>cmd,<EOL>shell=shell,<EOL>stderr=subprocess.PIPE,<EOL>stdout=subprocess.PIPE,<EOL>creationflags=<NUM_LIT:0>,<EOL>bufsize=<NUM_LIT:1>,<EOL>cwd=cwd,<EOL>)<EOL>all_output = []<EOL>code = None<EOL>line = None<EOL>while code is None:<EOL><INDENT>code = proc.poll()<EOL>if callback and callable(callback):<EOL><INDENT>line = console_to_str(proc.stderr.read(<NUM_LIT>))<EOL>if line:<EOL><INDENT>callback(output=line, timestamp=datetime.datetime.now())<EOL><DEDENT><DEDENT><DEDENT>if callback and callable(callback):<EOL><INDENT>callback(output='<STR_LIT:\r>', timestamp=datetime.datetime.now())<EOL><DEDENT>lines = filter(None, (line.strip() for line in proc.stdout.readlines()))<EOL>all_output = console_to_str(b'<STR_LIT:\n>'.join(lines))<EOL>if code:<EOL><INDENT>stderr_lines = filter(None, (line.strip() for line in proc.stderr.readlines()))<EOL>all_output = console_to_str(b'<STR_LIT>'.join(stderr_lines))<EOL><DEDENT>output = '<STR_LIT>'.join(all_output)<EOL>if code != <NUM_LIT:0> and check_returncode:<EOL><INDENT>raise exc.CommandError(output=output, returncode=code, cmd=cmd)<EOL><DEDENT>return output<EOL>
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