On Nov 4, 3:08 pm, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
>
> 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.

And at the beginning, it would appear, because this also works:

:echo system('echo "a b c"')

> 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.
>

The case you found where it breaks is probably more common than would
appear at first glance, though I did not realize it was so specific.

There is a line in the script I mentioned working on (http://
www.vim.org/scripts/script.php?script_id=2378):

        let s:lint = system(shellescape(g:mlint_path_to_mlint) . " " .
shellescape(b:mlintTempDir . s:filename))

In my testing, I had set g:mlint_path_to_mlint to something in my
"Program Files" directory (hence the need for a double quote) and
s:filename contained "Copy of startup.m" (also, a need for the double
quote).

There may be a much better way to accomplish this (which I'd love to
hear), but nevertheless using system() to invoke an external program
in Windows with a potentially space-infused path, and then passing
this program an argument similarly infused with spaces (such as a file
path), is potentially very useful.

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

I doubt that changing the default would break anything built into Vim,
but I suppose that remains to be seen. Changing the default would
certainly add a whole class of use cases that work "out of the box".
Any corner cases that for some reason do not work properly could
easily be worked around as done in the plugin mentioned, by setting
and restoring shellxquote (and possibly shellcmdflag). I haven't found
a way to break system() with shellxquote=\", but there is certainly a
way to break it with the current default. I have admittedly not done
much with shellxquote for uses other than system(). I see potential
for a problem here, especially when using redirection, but I _think_
it will work.

Plugins are another question though. For testing, I placed my proposed
values of shellxquote and shellcmdflag in my vimrc, and immediately
broke the TagList plugin.

This seems to be caused by a bug in TagList, actually. I don't think
the following code is needed, and it is the root of the bug. But, I'm
not actually sure what the intent of it is:

    if &shellxquote == '"'
        " Double-quotes within double-quotes will not work in the
        " command-line.If the 'shellxquote' option is set to double-
quotes,
        " then escape the double-quotes in the ctags command-line.
        let ctags_cmd = escape(ctags_cmd, '"')
    endif

Later (in Windows), Taglist writes ctags_cmd to a temporary batch file
and executes the batch file with system().

I wonder how many other plugins do something similar.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui