In Vim, What is the best (portable and fast) way to read output of a shell command? This output may be binary and thus contain nulls and (not) have trailing newline which matters. Current solutions I see:
- Use
system()
. Problems: does not work with NULLs. - Use
:read !
. Problems: won’t save trailing newline, tries to be smart detecting output format (dos/unix/mac). - Use
!
with redirection to temporary file, thenreadfile(, "b")
to read it. Problems: two calls for fs,shellredir
option also redirects stderr by default and it should be less portable ('shellredir'
is mentioned here because it is likely to be set to a valid value). - Use
system()
and filter outputs throughxxd
. Problems: very slow, least portable (no equivalent of'shellredir'
for pipes).
Any other ideas?