def StartProcess(executable_name, clangd_log_path=None):
if not clangd_log_path or not log.logger.isEnabledFor(log.DEBUG):
clangd_log_path = os.devnull
fdClangd = open(clangd_log_path, 'w+')
# fix executable file name under windows (both cygwin and native win32)
if sys_platform == 'msys' or sys_platform == 'win32':
if not executable_name.endswith('.exe'):
executable_name += '.exe'
# apply platform-specific hacks
if sys_platform != 'win32':
# for posix or cygwin
fdInRead, fdInWrite = Pipe()
fdOutRead, fdOutWrite = Pipe()
SetCloseOnExec(fdInWrite)
SetCloseOnExec(fdOutRead)
else:
# only native win32
fdInRead, fdInWrite = Win32SocketPair()
fdOutRead, fdOutWrite = Win32SocketPair()
cwd = os.path.dirname(executable_name)
# apply native win32's hack
if sys_platform == 'win32':
# we need hide this subprocess's window under windows, or it opens a new visible window
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
clangd = Popen(
executable_name,
stdin=fdInRead,
stdout=fdOutWrite,
stderr=fdClangd,
cwd=cwd,
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP,
startupinfo=startupinfo)
else:
clangd = Popen(
executable_name,
stdin=fdInRead,
stdout=fdOutWrite,
stderr=fdClangd,
cwd=cwd)
return clangd, fdInWrite, fdOutRead, fdClangd
评论列表
文章目录