def get_plink_version():
    """Gets the Plink version from the binary.

    :returns: the version of the Plink software
    :rtype: str

    This function uses :py:class:`subprocess.Popen` to gather the version of
    the Plink binary. Since executing the software to gather the version
    creates an output file, it is deleted.

    .. warning::
        This function only works as long as the version is returned as
        ``| PLINK! | NNN |`` (where, ``NNN`` is the version), since we use
        regular expresion to extract the version number from the standard
        output of the software.

    """
    # Running the command
    tmp_fn = None
    with tempfile.NamedTemporaryFile(delete=False) as tmpfile:
        tmp_fn = tmpfile.name + "_pyGenClean"

    # The command to run
    command = ["plink", "--noweb", "--out", tmp_fn]

    output = None
    try:
        proc = Popen(command, stdout=PIPE, stderr=PIPE)
        output = proc.communicate()[0].decode()
    except OSError:
        raise ProgramError("plink: command not found")

    # Deleting the output file automatically created by Plink
    if os.path.isfile(tmp_fn + ".log"):
        os.remove(tmp_fn + ".log")

    # Finding the version
    version = re.search(r"\|\s+PLINK!\s+\|\s+(\S+)\s+\|", output)
    if version is None:
        version = "unknown"
    else:
        version = version.group(1)

    return version