0

I'm currently using gvim 8.0 on Windows 10. When I try to do the following command,

:echo system('echo %PATH%')

I get the following error.

E484: Can't open file C:/Users/BITS_A~1/AppData/Local/Temp/VIoBE39.tmp

Why would vim try to open a file even when it just needs to echo the PATH variable, and why is it changing my user directory name, bits_and_scraps, to BITS_A~1?

By the way,

:echo %PATH%

works perfectly from my cmd.

2

It sounds like you've overridden some of the settings used to invoke external programs. Is your Vim set up so programs run in either Cygwin or Windows Linux Subsystem by any chance?

Try starting vim with -u NONE -i none. Alternatively run these after starting vim:

:set shell&
:set shellxquote&
:set shellxescape&
:set shellcmdflag&
:set shellredir&
:set shellslash&

Does it work now? If not try :set verbose=5 and run again. What does it say?

Vim saves the output of system() to a temporary file before doing anything further (such as displaying the result in the Vim window). Looks like the error you are seeing is caused by having Unix style paths configured. Windows doesn't know how to interpret such paths so the write to temporary file fails.

Update: I was finally able to reproduce this. The shell settings (i.e. those related to / vs \) are only part of the story. There is also a quoting issue. Try :echo system('echo "%PATH%"'). That solved the problem for me. Evaluation of the parameter passed to system() is not as I originally assumed.

I guess there are characters in our PATH var, encountered by Vim as it builds the redirect, that are special to Vim...by quoting them they lose their special meaning (as is often the case in shells). (And that error message about opening the temp file became a bit misleading once the slashes were fixed.)

Anyways, hopefully you can get things working now.

  • Now I get why it was trying to do things with tmp files. But it still does not work. After I changed the verbose setting, it says Calling shell to execute: "echo %PATH% >C:\Users\BITS_A~1\AppData\Local\Temp\VIo577.tmp 2>&1" – bits_and_scraps Sep 25 '17 at 5:40
  • You still have a Unix artifact: 2>&1. Are you sure you reset all of the 'shell*' settings? In particular 'shellredir'. For sh, bash, etc. the value would be something like... >%s 2>&1. You could try explicitly setting it to a Win compatible value: :set shellredir=> – B Layer Sep 25 '17 at 7:30
  • I think the default value for shellredir of my gVim is '>%s 2>&1'(checked using :set shellredir?). I've changed it to '>'. Now it says E484: Can't open file C:\Users\BITS_A~1\AppData\Local\Temp\VIoCC24.tmp. – bits_and_scraps Sep 25 '17 at 8:43
  • You have a lot of Windows incompatible settings it seems. I don't know why you are getting 8.3 paths (the shortened paths with ~). Instead of modifying all the settings manually, did you test it after starting vim with -u NONE -i NONE? I suggest you do that as it'll not load any of your plugins or vimrc settings. Good way to rule out any of your customizations. (But still do verbose=5.) – B Layer Sep 25 '17 at 9:57
  • Even with -u NONE -i NONE vim still has the same path problem. With the default shellredir value. Calling shell to execute: "echo %PATH% >C:\Users\BITS_A~1\AppData\Local\Temp\VIoFC62.tmp 2>&1 E484: Can't open file C:\Users\BITS_A~1\AppData\Local\Temp\VIoFC62.tmp With shellredir set to >. Calling shell to execute: "echo %PATH% > C:\Users\BITS_A~1\AppData\Local\Temp\VIo1F82.tmp E484: Can't open file C:\Users\BITS_A~1\AppData\Local\Temp\VIo1F82.tmp – bits_and_scraps Sep 25 '17 at 12:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.