Skip to content

Commit

Permalink
Fix pid functions with cygwin shells
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Yu-chen Kao (cybeliak) authored and tpope committed Jan 20, 2015
1 parent c4390c5 commit 77455b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion autoload/dispatch.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion autoload/dispatch/windows.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 77455b9

Please sign in to comment.