From 77455b92048bb00fef752be1218a174a05d0c2b6 Mon Sep 17 00:00:00 2001 From: "Yu-chen Kao (cybeliak)" Date: Fri, 26 Dec 2014 13:00:22 +0800 Subject: [PATCH] Fix pid functions with cygwin shells The actually problem is that vim automatically set &shellquote='"' when &shell is some kind of posix-like shells. When &shellquote is '"', writing double quotes in the command passed to system() would cause the command to be misinterpreted, and producing the weird error as reported in #108. The solution is to detect whether shellquote is set to double quote, and alter the sent command accordingly. Note that this issue would not affect default windows cmd shell, thus the command should only be altered when *sh shells are used. Fixes #108. --- autoload/dispatch.vim | 6 +++++- autoload/dispatch/windows.vim | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/autoload/dispatch.vim b/autoload/dispatch.vim index 2a18921..212e8d6 100644 --- a/autoload/dispatch.vim +++ b/autoload/dispatch.vim @@ -581,7 +581,11 @@ function! s:running(pid) abort if !a:pid return 0 elseif has('win32') - return system('tasklist /fi "pid eq '.a:pid.'"') =~# '===' + let tasklist_cmd = 'tasklist /fi "pid eq '.a:pid.'"' + if &shellxquote ==# '"' + let tasklist_cmd = substitute(tasklist_cmd, '"', "'", "g") + endif + return system(tasklist_cmd) =~# '===' else call system('kill -0 '.a:pid) return !v:shell_error diff --git a/autoload/dispatch/windows.vim b/autoload/dispatch/windows.vim index f571d3d..71fad90 100644 --- a/autoload/dispatch/windows.vim +++ b/autoload/dispatch/windows.vim @@ -71,9 +71,14 @@ function! dispatch#windows#start(request) abort endfunction function! dispatch#windows#activate(pid) abort - if system('tasklist /fi "pid eq '.a:pid.'"') !~# '===' + let tasklist_cmd = 'tasklist /fi "pid eq '.a:pid.'"' + if &shellxquote ==# '"' + let tasklist_cmd = substitute(tasklist_cmd, '"', "'", "g") + endif + if system(tasklist_cmd) !~# '===' return 0 endif + if !exists('s:activator') let s:activator = tempname().'.vbs' call writefile(['WScript.CreateObject("WScript.Shell").AppActivate(WScript.Arguments(0))'], s:activator)