<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run_command(cmd, *args, **kwargs):
 """ Take an input command and run it, handling exceptions and error codes and returning its stdout and stderr. :param cmd: The list of command and arguments. :type cmd: list :returns: A 2-tuple of the output and error from the command :rtype: Tuple[str, str] :raises: exceptions.PipenvCmdError """


    from pipenv.vendor import delegator
    from ._compat import decode_for_output
    from .cmdparse import Script
    catch_exceptions = kwargs.pop("catch_exceptions", True)
    if isinstance(cmd, (six.string_types, list, tuple)):
        cmd = Script.parse(cmd)
    if not isinstance(cmd, Script):
        raise TypeError("Command input must be a string, list or tuple")
    if "env" not in kwargs:
        kwargs["env"] = os.environ.copy()
    kwargs["env"]["PYTHONIOENCODING"] = "UTF-8"
    try:
        cmd_string = cmd.cmdify()
    except TypeError:
        click_echo("Error turning command into string: {0}".format(cmd), err=True)
        sys.exit(1)
    if environments.is_verbose():
        click_echo("Running command: $ {0}".format(cmd_string, err=True))
    c = delegator.run(cmd_string, *args, **kwargs)
    return_code = c.return_code
    if environments.is_verbose():
        click_echo("Command output: {0}".format(
            crayons.blue(decode_for_output(c.out))
        ), err=True)
    if not c.ok and catch_exceptions:
        raise PipenvCmdError(cmd_string, c.out, c.err, return_code)
    return c