Skip to content

Commit 77455b9

Browse files
Yu-chen Kao (cybeliak)tpope
authored andcommitted
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.
1 parent c4390c5 commit 77455b9

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

autoload/dispatch.vim

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,11 @@ function! s:running(pid) abort
581581
if !a:pid
582582
return 0
583583
elseif has('win32')
584-
return system('tasklist /fi "pid eq '.a:pid.'"') =~# '==='
584+
let tasklist_cmd = 'tasklist /fi "pid eq '.a:pid.'"'
585+
if &shellxquote ==# '"'
586+
let tasklist_cmd = substitute(tasklist_cmd, '"', "'", "g")
587+
endif
588+
return system(tasklist_cmd) =~# '==='
585589
else
586590
call system('kill -0 '.a:pid)
587591
return !v:shell_error

autoload/dispatch/windows.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ function! dispatch#windows#start(request) abort
7171
endfunction
7272

7373
function! dispatch#windows#activate(pid) abort
74-
if system('tasklist /fi "pid eq '.a:pid.'"') !~# '==='
74+
let tasklist_cmd = 'tasklist /fi "pid eq '.a:pid.'"'
75+
if &shellxquote ==# '"'
76+
let tasklist_cmd = substitute(tasklist_cmd, '"', "'", "g")
77+
endif
78+
if system(tasklist_cmd) !~# '==='
7579
return 0
7680
endif
81+
7782
if !exists('s:activator')
7883
let s:activator = tempname().'.vbs'
7984
call writefile(['WScript.CreateObject("WScript.Shell").AppActivate(WScript.Arguments(0))'], s:activator)

0 commit comments

Comments
 (0)