def execute(cmd, cwd=None):
    """ Execute a command and return it's output. """
    try:
        lines = subprocess \
            .check_output(cmd, cwd=cwd, stderr=DEVNULL) \
            .splitlines()
    except subprocess.CalledProcessError:
        return None
    else:
        if lines:
            return decode(lines[0].strip())
        else:
            return None
Execute a command and return it's output.