Hello Vim developers,
Sorry for touching that can of worms again, but I've come upon a problem with
the changed 'shellxquote' option on Windows (patch 7.3.443 (MS-Windows: 'shcf'
and 'sxq' defaults are not very good) and the few patches following it. Here's
the discussion as a refresher:
http://groups.google.com/group/vim_dev/browse_thread/thread/bd53b29c5e5f2a50/be11dca5e9d501bb)
The problem:
#v+
vim -N -u NONE
:echo system('echo.hi(ho)hi')
E484: Can't open file D:\temp\VIo408F.tmp
#v-
It's the unquoted parentheses in the command. My actual command was
:echo system('icacls ' . shellescape('C:\foo') . ' /deny
%userdomain%\%username%:(WD,AD,DC)')
The problem lies in the way the command is passed to the shell, as the following
experiments show:
#v+
REM This is how Vim passes the command with shcf=/c and sxq=(
C:\> C:\Windows\system32\cmd.exe /c (echo.hi^(ho^)hi ^>D:\temp\VIo8945.tmp 2^>^&1)
hi was unexpected at this time.
REM Enclosing the entire parenthesized command in double quotes avoids the
error, but breaks the redirection.
C:\> C:\Windows\system32\cmd.exe /c "(echo.hi^(ho^)hi ^>D:\temp\VIo8945.tmp 2^>^&1)"
hi(ho)hi >D:\temp\VIo8945.tmp 2>&1
REM Enclosing the command without the redirection in double quotes and
parentheses seems to work.
C:\> C:\Windows\system32\cmd.exe /c "(echo.hi^(ho^)hi)" ^>D:\temp\VIo8945.tmp 2^>^&1
REM Best recommendation is probably to always quote all arguments, even when not
necessary in a plain shell.
C:\> C:\Windows\system32\cmd.exe /c (echo.^"hi^(ho^)hi^" ^>D:\temp\VIo8945.tmp
2^>^&1)
#v-
Therefore, every argument should be quoted; this works:
:echo system('icacls ' . shellescape('C:\foo') . ' /deny ' .
shellescape('%userdomain%\%username%:(WD,AD,DC)'))
I know that the arcane quoting rules of cmd.exe are to blame for this mess. It
was a real hassle to get from the E484 to the root cause of this (in Vim 7.3.000
(with the old quoting implementation), my command worked fine); something I'd
rather avert from others, so hopefully my findings will be helpful in some way.
It seems like an intractable problem that has no perfect solution.
#v+
Windows 7 SP1 Ultimate 64-bit English
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Feb 20 2013 15:34:49)
MS-Windows 64-bit GUI version with OLE support
Included patches: 1-823
Compiled by
in...@karkat.de
Huge version with GUI. Features included (+) or not (-):
#v-
-- regards, ingo
--
-- Ingo Karkat -- /^-- /^-- /^-- /^-- /^-- /^--
http://ingo-karkat.de/ --
--
http://vim.sourceforge.net/account/profile.php?user_id=9713 --