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

gsudo Tee hangs when used to save files from Vim #25

Closed
ecsousa opened this issue Mar 5, 2020 · 7 comments
Closed

gsudo Tee hangs when used to save files from Vim #25

ecsousa opened this issue Mar 5, 2020 · 7 comments

Comments

@ecsousa
Copy link

ecsousa commented Mar 5, 2020

I'm trying to reproduce the trick of saving files using sudo from a non-root vim using gsudo. However, gsudo hangs.

Here's the steps:

  1. Open a protected file (that requires elevation to be writeen) with a non-elevated vim.exe or gvim.exe
  2. Change the file
  3. Execute the command in vim: :w !gsudo tee %

Expected result: file should be save with chagnes

Actual result: command hangs

Notes

  • you'll also need to have tee installed (either cygwin, msys, etc).
  • I've tried using only :w !tee % (for non protected file). It works fine, which indicates that the issue is indeed on gsudo

Here's some reference on how this trick works on unix/linux: https://vim.fandom.com/wiki/Su-write

@gerardog
Copy link
Owner

gerardog commented Mar 5, 2020

Does :w !tee SomeFile.txt works for you? (no gsudo call, and let SomeFile.txt be writeable by a normal user)
Which version of Vim are you using? What is your vimrc file like?

I need a working combination of Vim+Tee first, and then I'll be able to test why gsudo is hanging.
I installed Vim and all !cmd commands are failing for me, including :w !tee % or !cmd.exe

image

or on gvim:
image

@gerardog
Copy link
Owner

gerardog commented Mar 5, 2020

Powershell's tee command works with gsudo:

PS C:\test> Write-Output 1234 | gsudo tee MyFile.txt

@ecsousa
Copy link
Author

ecsousa commented Mar 5, 2020

Here's versions and configurations I'm using:

  • Vim: 8.2.352 (installed using chocolatey)
  • Tee: tee.exe from VIM runtime dir (in path)
  • Gsudo: 0.6.0.3 (installed using chocolatey)
  • Vimrc: .vim directory from https://github.com/ecsousa/.vim (in windows, cloned into ~/vimfiles)

From your screen shots, it seems you've configured Vim to use PowerShell instead of CMD as shell for external commands -- however, Powershell don't have the < operator for stdin redirect, which is causing error.

Using CMD as Vim's shell, vim.exe hangs like this, after approving UAC prompt:

image

Results from gvim.exe is better, as it shows the command line Vim tried to execute (also after UAC prompt):

image

@ecsousa
Copy link
Author

ecsousa commented Mar 5, 2020

Executing a command like this in CMD also freezes:

gsudo tee t2.txt < t1.txt

Note: using only tee t2.txt < t1.txt works without issue

@gerardog
Copy link
Owner

gerardog commented Mar 5, 2020

Try this version.
https://ci.appveyor.com/project/gerardog/gsudo/builds/31254742/artifacts

This seems to fix the 'it hangs' issue. Nonetheless, I found another one while testing tee: If you redirect at least one but not all of StdOut/StdIn/StdErr, then those not redirected are not correctly forwarded...
This fix may allow you to save as admin on vim, but still doesn't makes tee work properly on all scenarios.

@ecsousa
Copy link
Author

ecsousa commented Mar 5, 2020

Just tested, and is working as expected now. Thank you very much for the quick fix!

@ecsousa ecsousa closed this as completed Mar 5, 2020
@gerardog
Copy link
Owner

gerardog commented Mar 5, 2020

Thanks for confirming. This will be released in 0.7

@gerardog gerardog changed the title gsudo hangs when used to save files from Vim gsudo Tee hangs when used to save files from Vim Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants