Runs a command and returns the result, that would be written to `stdout`, as a string. The output itself can
    be suppressed.

    :param cmd: Command to run.
    :type cmd: unicode
    :param expected_errors: If the return code is non-zero, but found in this tuple, it will be ignored. ``None`` is
      returned in this case.
    :type expected_errors: tuple
    :param shell: Use a shell.
    :type shell: bool
    :param sudo: Use `sudo`.
    :type sudo: bool
    :param quiet: If set to ``True``, does not show any output.
    :type quiet: bool
    :return: The result of the command as would be written to `stdout`.
    :rtype: unicode

def stdout_result(cmd, expected_errors=(), shell=True, sudo=False, quiet=False):
    """
    Runs a command and returns the result, that would be written to `stdout`, as a string. The output itself can
    be suppressed.

    :param cmd: Command to run.
    :type cmd: unicode
    :param expected_errors: If the return code is non-zero, but found in this tuple, it will be ignored. ``None`` is
      returned in this case.
    :type expected_errors: tuple
    :param shell: Use a shell.
    :type shell: bool
    :param sudo: Use `sudo`.
    :type sudo: bool
    :param quiet: If set to ``True``, does not show any output.
    :type quiet: bool
    :return: The result of the command as would be written to `stdout`.
    :rtype: unicode
    """
    which = operations.sudo if sudo else operations.run
    with hide('warnings'):
        result = which(cmd, shell=shell, quiet=quiet, warn_only=True)
    if result.return_code == 0:
        return result

    if result.return_code not in expected_errors:
        error("Received unexpected error code {0} while executing!".format(result.return_code))
    return None