def command_output(<EOL>self, command, shell=False, capture_stderr=False, localized=False<EOL>):
<EOL>if isinstance(command, basestring):<EOL><INDENT>pretty_cmd = command<EOL><DEDENT>else:<EOL><INDENT>pretty_cmd = "<STR_LIT:U+0020>".join(command)<EOL><DEDENT>if not shell and isinstance(command, basestring):<EOL><INDENT>command = shlex.split(command)<EOL><DEDENT>stderr = STDOUT if capture_stderr else PIPE<EOL>env = self._english_env if not localized else None<EOL>try:<EOL><INDENT>process = Popen(<EOL>command,<EOL>stdout=PIPE,<EOL>stderr=stderr,<EOL>close_fds=True,<EOL>universal_newlines=True,<EOL>shell=shell,<EOL>env=env,<EOL>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>msg = "<STR_LIT>".format(cmd=pretty_cmd, error=e)<EOL>raise exceptions.CommandError(msg, error_code=e.errno)<EOL><DEDENT>output, error = process.communicate()<EOL>if self._is_python_2 and isinstance(output, str):<EOL><INDENT>output = output.decode("<STR_LIT:utf-8>")<EOL>error = error.decode("<STR_LIT:utf-8>")<EOL><DEDENT>retcode = process.poll()<EOL>if retcode:<EOL><INDENT>if retcode == -<NUM_LIT:15>:<EOL><INDENT>msg = "<STR_LIT>"<EOL>self.log(msg.format(cmd=pretty_cmd))<EOL><DEDENT>else:<EOL><INDENT>msg = "<STR_LIT>"<EOL>output_oneline = output.replace("<STR_LIT:\n>", "<STR_LIT:U+0020>")<EOL>if output_oneline:<EOL><INDENT>msg += "<STR_LIT>"<EOL><DEDENT>msg = msg.format(cmd=pretty_cmd, error=retcode, output=output_oneline)<EOL>raise exceptions.CommandError(<EOL>msg, error_code=retcode, error=error, output=output<EOL>)<EOL><DEDENT><DEDENT>return output<EOL>
Run a command and return its output as unicode.
The command can either be supplied as a sequence or string.

:param command: command to run can be a str or list
:param shell: if `True` then command is run through the shell
:param capture_stderr: if `True` then STDERR is piped to STDOUT
:param localized: if `False` then command is forced to use its default (English) locale

A CommandError is raised if an error occurs