Benjamin Fritz wrote:

> I've been playing around with a plugin
> (http://www.vim.org/scripts/script.php?script_id=2378), trying to
> specify a path to the _command_ that is passed to system(). Since this
> command may have spaces in it, it needs to be wrapped in quotes.
> 
> However, if it is wrapped in quotes, the default settings of
> shellxquote on win32 do not work. This command will not do what is
> intended, for example:
> 
> cmd /c "C:\some path\some program.exe" "an argument"
> 
> If you set shellxquote to \" it does work. The command passed looks
> funny, but is actually desired:
> 
> cmd /c ""C:\some path\some program.exe" "an argument""
> 
> I think that shellxquote should default to \" on Windows always. I
> know of no case where it fails.
> 
> The reason for this behavior:
> 
> >From the help for cmd in Windows:
> 
> > If /C or /K is specified, then the remainder of the command line after
> > the switch is processed as a command line, where the following logic is
> > used to process quote (") characters:
> >
> >     1.  If all of the following conditions are met, then quote characters
> >         on the command line are preserved:
> >
> >         - no /S switch
> >         - exactly two quote characters
> >         - no special characters between the two quote characters,
> >           where special is one of: &<>()@^|
> >         - there are one or more whitespace characters between the
> >           the two quote characters
> >         - the string between the two quote characters is the name
> >           of an executable file.
> >
> >     2.  Otherwise, old behavior is to see if the first character is
> >         a quote character and if so, strip the leading character and
> >         remove the last quote character on the command line, preserving
> >         any text after the last quote character."
> 
> Both values of shellxquote, in this case, will fall into category 2.
> 
> Thus, the current default actually executes the command:
> 
> C:\some path\some program.exe" "an argument
> 
> Whereas, setting shellxquote to \" will execute:
> 
> "C:\some path\some program.exe" "an argument"
> 
> This is the desired command.
> 
> Normal commands would still work, for example, the command:
> 
> echo "abc def"
> 
> becomes:
> 
> cmd /c "echo "abc def""
> 
> which executes:
> 
> echo "abc def"
> 
> Again, just as desired.
> 
> This might not always work, because I think some versions of cmd.exe
> will strip the _closing_ quote instead of the _last_ quote. For the
> best possible compatibility, it is probably a good idea to also
> default shellcmdflag to "/s\ /c" instead of just "/c" in the same
> situation that "/c" currently applies. This will force the 2nd quote
> behavior given in the quoted cmd help.

I had some trouble reproducing the problem.  When both 'shellquote' and
'shellxquote' are emtpy and 'shell' is cmd.exe, this works fine:

        :echo system('"e:/mksnt/echo.exe" foo bar')

I finally figured out a way to break it:

        :echo system('"e:/mksnt/echo.exe" "foo bar"')

The double quote at the end is essential.
It appears cmd.exe strips the first and last double quote and tries to
execute   e:/mksnt/echo.exe" "foo  .  Setting 'shellxquote' to a double
quote indeed helps to fix this.

Now the question is what will break if we change the default for
'shellxquote'.  I'm not sure about that.

-- 
If Microsoft would build a car...
... The airbag system would ask "are you SURE?" before deploying.

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui