def METHOD_NAME(program, envpath=None):
    env = os.environ.copy()
    if envpath:
        env["PATH"] = envpath
    # look up in $PATH
    for bin_dir in env.get("PATH", "").split(os.pathsep):
        if os.path.isfile(os.path.join(bin_dir, program)):
            return os.path.join(bin_dir, program)
        if IS_WINDOWS and os.path.isfile(os.path.join(bin_dir, "%s.exe" % program)):
            return os.path.join(bin_dir, "%s.exe" % program)
    # try OS's built-in commands
    try:
        result = exec_command(["where" if IS_WINDOWS else "which", program], env=env)
        if result["returncode"] == 0 and os.path.isfile(result["out"].strip()):
            return result["out"].strip()
    except OSError:
        pass
    return program