Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Created April 3, 2012 09:06
Show Gist options
  • Save eagletmt/2290573 to your computer and use it in GitHub Desktop.
Save eagletmt/2290573 to your computer and use it in GitHub Desktop.
python import vim, os
function! Spawn(argv)
python << EOM
argv = vim.eval('a:argv')
pid = os.spawnvp(os.P_NOWAIT, argv[0], argv)
vim.command('let pid = %d' % pid)
EOM
return pid
endfunction
function! Wait(pid)
python <<EOM
pid = int(vim.eval('a:pid'))
_, st = os.waitpid(pid, 0)
vim.command('let ret = %d' % os.WEXITSTATUS(st))
EOM
return ret
endfunction
function! Test()
let pid = Spawn(['/bin/sh', '-c', 'exit 42'])
echomsg 'pid =' pid
call system('sleep 3')
let st = Wait(pid)
echomsg 'ret =' st
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment