Created
January 29, 2018 13:09
-
-
Save lambdalisue/52d423d564272ceed81f0ca983c56133 to your computer and use it in GitHub Desktop.
system() by System.Job
This file contains 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:Job = vital#vital#import('System.Job') | |
function! s:_on_stdout(data) abort dict | |
let self.stdout[-1] .= a:data[0] | |
call extend(self.stdout, a:data[1:]) | |
endfunction | |
function! s:_on_stderr(data) abort dict | |
let self.stderr[-1] .= a:data[0] | |
call extend(self.stderr, a:data[1:]) | |
endfunction | |
function! s:system(...) abort | |
let job = s:Job.start(a:000, { | |
\ 'stdout': [''], | |
\ 'stderr': [''], | |
\ 'on_stdout': function('s:_on_stdout'), | |
\ 'on_stderr': function('s:_on_stderr'), | |
\}) | |
let exit_status = job.wait() | |
return { | |
\ 'exit_status': exit_status, | |
\ 'stdout': job.stdout, | |
\ 'stderr': job.stderr, | |
\} | |
endfunction | |
echo s:system('true') | |
echo s:system('false') | |
echo s:system('git', '-h') |
Author
lambdalisue
commented
Jan 29, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment