def run_cmd(cmd):
try:<EOL><INDENT>p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)<EOL>stdout, stderr = p.communicate()<EOL><DEDENT>except OSError as e:<EOL><INDENT>if DEBUG:<EOL><INDENT>raise<EOL><DEDENT>if e.errno == errno.ENOENT:<EOL><INDENT>msg = '<STR_LIT>'.format('<STR_LIT:U+0020>'.join(cmd))<EOL>raise _CommandNotFound(msg, cmd)<EOL><DEDENT>else:<EOL><INDENT>raise _AHBootstrapSystemExit(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'.format('<STR_LIT:U+0020>'.join(cmd), str(e)))<EOL><DEDENT><DEDENT>try:<EOL><INDENT>stdio_encoding = locale.getdefaultlocale()[<NUM_LIT:1>] or '<STR_LIT>'<EOL><DEDENT>except ValueError:<EOL><INDENT>stdio_encoding = '<STR_LIT>'<EOL><DEDENT>if not isinstance(stdout, _text_type):<EOL><INDENT>stdout = stdout.decode(stdio_encoding, '<STR_LIT:replace>')<EOL><DEDENT>if not isinstance(stderr, _text_type):<EOL><INDENT>stderr = stderr.decode(stdio_encoding, '<STR_LIT:replace>')<EOL><DEDENT>return (p.returncode, stdout, stderr)<EOL>
Run a command in a subprocess, given as a list of command-line
arguments.

Returns a ``(returncode, stdout, stderr)`` tuple.