Search code examples
scriptingvim

How to interact with an external command in vimscript?


I have a script which interacts with user (prints some questions to stderr and gets input from stdin) and then prints some data to stdout. I want to put the output of the script in a variable in vimscript. It probably should look like this:

let a = system("./script")

The supposed behaviour is that script runs, interacts with user, and after all a is assigned with its output to stdout. But instead a is assigned both with outputs to stdout and stderr, so user seed no prompts.

Could you help me fixing it?


Solution

  • Interactive commands are best avoided from within Vim; especially with GVIM (on Windows), a new console window pops up; you may not have a fully functional terminal, ...

    Better query any needed arguments in Vimscript itself (with input(); or pass them on from a custom Vim :command), and just use the external script non-interactively, feeding it everything it needs.