When I want to call an external program, I have the option of spawning a shell or not.

system('my command') will spawn a shell (executing your .bashrc/etc and all it seems).

system(['my command']) will execute the command without a shell, which seems like it's the faster and probably preferred method since you avoid any start up cost.

Imagine I have do_it installed to ~/totally/not/standard/bin/do_it, and I've added that a dir to my $PATH in my shell, so it normally works.

If I run system(['do_it']) it executes fine in nvim, where as I'd actually expect it to fail because without the shell, it shouldn't know where to find do_it.

Unless nvim is injecting/resolving the $PATH as it was when nvim loaded up. I can't run system(['echo $PATH']) to check because echo is a builtin.

  • Is this whats happening?

  • Is it safe to assume that if it works in system(string) it will work with system(list)?

    • Should I be doing exepath('do_it') first to get the full path without spawning a shell, then passing the full path to system(list)?
  • Why would I ever really want system(string) when it's so potentially magnitudes slower (if you have a heavy rc) and system(list) seems to inherit your environment anyway?

  • Does your system have /bin/echo ? You might still be able to echo path. But, at a guess, yes—neovim is a process like any other, and inherits env vars from its parent. It may choose to ignore them, but it may also quite reasonably use them (e.g. when launching it’s own processes) – D. Ben Knoble Feb 12 '19 at 14:18
  • For others who are not familar with this, see neovim.io/doc/user/eval.html#jobstart(). I think you can run :echo $PATH to see what $PATH is used for system([]). nvim inherits the environment variables from the shell it is invoked. This is why we use export when defining $PATH etc. You can list all environment variables marked with export by running $ export -p. – Hotschke Feb 13 '19 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.