EasyClangComplete: subprocess call throws OSError: [WinError 6] The handle is invalid on Windows

I’m trying to make work this promising plugin on win7 but for some reason the autocompletion isn’t working as showed up in your demo screencast, please take a look

I got clang3.9 installed and tweaked the user settings of the package (is it correct the path?) to point out to the directory where <vector> lives, what am I missing here?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 51 (48 by maintainers)

Commits related to this issue

Most upvoted comments

Solved, this fixed it:

utils.py

@staticmethod
def find_libclang_dir(clang_binary):
    """ Find directory with libclang

    Args:
        clang_binary (str): clang binary to call

    Returns:
        str: folder with libclang
    """
    stdin = None
    stderr = None
    log.debug(" platform: %s", platform.architecture())
    log.debug(" python version: %s", platform.python_version())
    for suffix in ClangUtils.get_suffixes():
        # pick a name for a file
        log.info(" we are on '%s'", platform.system())
        file = "libclang{}".format(suffix)
        log.info(" searching for: '%s'", file)
        startupinfo = None
        # let's find the library
        if platform.system() == "Darwin":
            # [HACK]: wtf??? why does it not find libclang.dylib?
            get_library_path_cmd = [clang_binary, "-print-file-name="]
        elif platform.system() == "Windows":
            get_library_path_cmd = [clang_binary, "-print-prog-name="]
            # Don't let console window pop-up briefly.
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            stdin = subprocess.PIPE
            stderr = subprocess.PIPE
        else:
            get_library_path_cmd = [clang_binary, "-print-file-name={}".format(file)]
        output = subprocess.check_output(
            get_library_path_cmd,
            stdin=stdin,
            stderr=stderr,
            startupinfo=startupinfo).decode('utf8').strip()
        log.info(" libclang search output = '%s'", output)
        if output:
            libclang_dir = ClangUtils.dir_from_output(output)
            if path.isdir(libclang_dir) and path.exists(path.join(libclang_dir, file)):
                log.info(" found libclang dir: '%s'", libclang_dir)
                log.info(" found library file: '%s'", file)
                ClangUtils.libclang_name = file
                return libclang_dir
        log.warning(" clang could not find '%s'", file)
    # if we haven't found anything there is nothing to return
    log.error(" no libclang found at all")
    return None

tools.py

@staticmethod
def run_command(command, shell=True):
    """ Run a generic command in a subprocess

    Args:
        command (str): command to run

    Returns:
        str: raw command output
    """
    try:
        stdin = None
        startupinfo = None
        if isinstance(command, list):
            command = subprocess.list2cmdline(command)
            log.debug(" command: \n%s", command)
        if platform.system() == "Windows":
            # Don't let console window pop-up briefly.
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            stdin = subprocess.PIPE
        output = subprocess.check_output(command,
                                         stdin=stdin,
                                         stderr=subprocess.STDOUT,
                                         shell=shell,
                                         startupinfo=startupinfo)
        output_text = ''.join(map(chr, output))
    except subprocess.CalledProcessError as e:
        output_text = e.output.decode("utf-8")
        log.debug(" clang process finished with code: %s", e.returncode)
        log.debug(" clang process output: \n%s", output_text)
    return output_text

Credits for this workaround/fix goes for @wbond