def get_cli_output(args):
import sys<EOL>from io import StringIO<EOL>command = args[<NUM_LIT:0>]<EOL>other_args = list(args[<NUM_LIT:1>:])<EOL>if command.startswith('<STR_LIT>'):<EOL><INDENT>command = command[<NUM_LIT:4>:]<EOL><DEDENT>exitcode = None<EOL>old_argv = sys.argv<EOL>new_argv = ['<STR_LIT>' % command] + other_args<EOL>sys.argv = new_argv<EOL>try:<EOL><INDENT>with tempfile.TemporaryFile(bufsize=<NUM_LIT:0>, prefix='<STR_LIT>') as tf:<EOL><INDENT>new_fileno = tf.fileno()<EOL>old_fileno = sys.stdout.fileno()<EOL>old_fileno_dupe = os.dup(old_fileno)<EOL>sys.stdout.flush()<EOL>os.dup2(new_fileno, old_fileno)<EOL>try:<EOL><INDENT>try:<EOL><INDENT>from rez.cli._main import run<EOL>run(command)<EOL><DEDENT>except SystemExit as e:<EOL><INDENT>exitcode = e.args[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>sys.stdout.flush()<EOL>tf.flush()<EOL>os.dup2(old_fileno_dupe, old_fileno)<EOL><DEDENT>tf.seek(<NUM_LIT:0>, os.SEEK_SET)<EOL>output = tf.read()<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>sys.argv = old_argv<EOL><DEDENT>return output, exitcode<EOL>
Invoke the named command-line rez command, with the given string
    command line args

    Note that it does this by calling rez.cli._main.run within the same
    python process, for efficiency; if for some reason this is not sufficient
    encapsulation / etc, you can use subprocess to invoke the rez as a
    separate process

    Returns
    -------
    stdout : basestring
        the captured output to sys.stdout
    exitcode : int
        the returncode from the command