<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_cmd(cmd, out=os.path.devnull, err=os.path.devnull):
 """Runs an external command :param list cmd: Command to run. :param str out: Output file :param str err: Error file :raises: RuntimeError """


    logger.debug(' '.join(cmd))
    with open(out, 'w') as hout:
        proc = subprocess.Popen(cmd, stdout=hout, stderr=subprocess.PIPE)
        err_msg = proc.communicate()[1].decode()
    with open(err, 'w') as herr:
        herr.write(str(err_msg))
    msg = '({}) {}'.format(' '.join(cmd), err_msg)
    if proc.returncode != 0:
        logger.error(msg)
        raise RuntimeError(msg)