Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gVim in windows(10): external command cannot keep current work directory #5104

Open
lymslive opened this issue Oct 22, 2019 · 7 comments
Open

Comments

@lymslive
Copy link

lymslive commented Oct 22, 2019

_Instructions: I switch to work in windows, find this problem that different from in linux.

Describe the bug
When execute external command, include :!cmd, :call system('cmd') and :terminal,
the current directory is always jump to c:\windows\system32

To Reproduce
Detailed steps to reproduce the behavior:

  1. Run gvim c:\users\me\_vimrc (or open gvim to edit any plain file)
  2. Type :!dir will list lost of file in c:\windows\system32
  3. Type ':terminal' will open a cmd shell with pwd is c:\windows\system32
  4. I've install gtags plugin, :!global -pq' cannot find the GTAGS of my project, also output c:\windows\system32`

Expected behavior
External command should keep current directory, as in linux do.

Environment (please complete the following information):

  • Vim version (8.1, download binaray from office website vim.org)
  • OS: windows10

**Addition:

  • It still happens when start gvim by `gvim --clean'
  • I've try set shell=powershell, not solved either
@k-takata
Copy link
Member

Does it happen when you execute Vim with gvim --clean?

@chrisbra
Copy link
Member

Have you tried the build from vim/vim-win32-installer?

@lymslive
Copy link
Author

I've just download the latest release from https://github.com/vim/vim-win32-installer/releases
but now solve my problem.

I also try :set shellcmdflag=/d\ /c, but the /d flag to cmd.exe seams not take effect.
However when try neovim, add /d flag to &shellcmdflag, it work!
(yes, the cmd.exe in my windows system has a autorun to change current directory to system32, /d should disable it)

maybe this is bug where fixed in neovim?

@k-takata
Copy link
Member

I suspect that this is caused by your settings or plugins. Please try with gvim --clean as I wrote above.

@lymslive
Copy link
Author

I suspect that this is caused by your settings or plugins. Please try with gvim --clean as I wrote above.

I've try it, it not the reason.

@k-takata
Copy link
Member

Ah, I'm not aware that you edited the comment.
Then, does :pwd show the correct directory?

@lymslive
Copy link
Author

I'v try many cases and will summarize some report:

After read cmd /? help, I found there is a autorun action due to registry HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun which will cd c:\windows\system32', and the /d` switch will disable such autorun.

As I have no privilege to delete the AutoRun registry, I first try to change the vim option :set shellcmdflag=/d\ /c, but not solve it as mentioned above. Because in vim the external command is run through vimrun.exe, and this vimrun.exe seems also subject to that AutoRun registry cd to c:\windows\system32'. Finally I delete(rename) vimrun.exe, then in vim the system()function will work for my plugin, while:!` command has different behavior but not import.

** Summary option setting:

set shellcmdflag=/d\ /c
set noshelltemp

and disable vimrun.exe

** Conclusion / Suggestion

It is tricky vimrun.exe subject to AutoRun registry, it's better to imply /d switch to run cmd.exe .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants