Created
August 20, 2014 05:28
-
-
Save blindFS/aee91526b9f30c577e5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:vimproc = vimproc#pgroup_open("sleep 10 | echo 'hello'") | |
call s:vimproc.stdin.close() | |
let s:result = "" | |
augroup vimproc_async_test | |
execute "autocmd! CursorHold,CursorHoldI * call" | |
\ "s:receive_vimproc_result()" | |
augroup END | |
function! s:receive_vimproc_result() | |
if !has_key(s:, "vimproc") | |
return | |
endif | |
let vimproc = s:vimproc | |
try | |
if !vimproc.stdout.eof | |
let s:result .= vimproc.stdout.read(1000, 0) | |
endif | |
if !vimproc.stderr.eof | |
let s:result .= vimproc.stderr.read(1000, 0) | |
endif | |
if !(vimproc.stdout.eof && vimproc.stderr.eof) | |
return 0 | |
endif | |
catch | |
echom v:throwpoint | |
endtry | |
augroup vimproc_async_test | |
autocmd! | |
augroup END | |
call vimproc.stdout.close() | |
call vimproc.stderr.close() | |
call vimproc.waitpid() | |
echom s:result | |
unlet s:vimproc | |
unlet s:result | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment