Search code examples
vimjobsio-redirection

vim8: redirect stdout in job


why does this not work:

:call job_start('echo hello > /tmp/file.txt')

I would expect that this creates a file called file.txt in /tmp with the content hello.

How can I make it work?


Solution

  • The reason that happens is because the command is executed directly and not through a shell.

    To have your intended behaviour, use the way the help pages (:help job_start) tell us to:

    :call job_start(["/bin/sh", "-c", "echo hello > /tmp/file.txt"])