execute command from vim in windows

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

execute command from vim in windows

cyboman
i need to run an executable from vim. the problem that i'm facing is
that directory names in the path to this file contain spaces and vim
doesn't recognize that.

here is the problem
C:\Documents and Settings\myhomedirectory\someotherdirectory
\executable.exe

when i execute from vim
!C:\\Documents\ and\ Settings\\myhomedirectory\\someotherdirectory\
\executable.exe

i get the following message

C:\\Documents

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Ben Schmidt
On 28/04/11 3:39 AM, cyboman wrote:

> i need to run an executable from vim. the problem that i'm facing is
> that directory names in the path to this file contain spaces and vim
> doesn't recognize that.
>
> here is the problem
> C:\Documents and Settings\myhomedirectory\someotherdirectory
> \executable.exe
>
> when i execute from vim
> !C:\\Documents\ and\ Settings\\myhomedirectory\\someotherdirectory\
> \executable.exe
>
> i get the following message
>
> C:\\Documents

I wonder what happened to the rest of the message.

Anyway...

I think it's because Vim basically passes the commandline to cmd.exe
which doesn't understand backslash escapes. Try enclosing in double
quotes instead.

!"C:\\Documents and Settings\\home\\otherdir\\executable.exe"

Not sure about doubling the backslashes, but I think it's
'optional'--but maybe it would work better without, so if the above
doesn't work, maybe try single backslashes.

Ben.



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Tony Mechelynck
In reply to this post by cyboman
On 27/04/11 19:39, cyboman wrote:

> i need to run an executable from vim. the problem that i'm facing is
> that directory names in the path to this file contain spaces and vim
> doesn't recognize that.
>
> here is the problem
> C:\Documents and Settings\myhomedirectory\someotherdirectory
> \executable.exe
>
> when i execute from vim
> !C:\\Documents\ and\ Settings\\myhomedirectory\\someotherdirectory\
> \executable.exe
>
> i get the following message
>
> C:\\Documents
>

One of the ways to avoid spaces in Windows names of files and
directories is to replace any "controversial" names by their 8.3
equivalents: for instance,

        :!C:/DOCUME~1/myhomedirectory/someotherdirectory/executable.exe

or even

        :!C:/PROGRA~1/foo/foo.exe C:/DOCUME~1/luser/MYDOCU~1/bar.txt

-- the latter is a program name with a file as argument, and would do
the same as running

        "C:\Program Files\foo\foo.exe" "C:\Documents and Settings\luser\My
Documents\bar.txt"

at the cmd.exe prompt. As you can see, 8.3 elements and LFN elements can
be used in a single path. Also (if 'shellslash' is off, which is the
default) you can use forward slashes as path separators, Vim will pass
them as backslashes to the shell.


Best regards,
Tony.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Ben Schmidt
> One of the ways to avoid spaces in Windows names of files and
> directories is to replace any "controversial" names by their 8.3
> equivalents

Of course, this will only work on filesystems that still support 8.3
equivalents and have that functionality turned on, which isn't always
the case these days. Just a potential gotcha with that approach.

Ben.



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

cyboman
In reply to this post by Ben Schmidt
thanks for the help

On Wed, Apr 27, 2011 at 8:53 PM, Ben Schmidt <[hidden email]> wrote:
On 28/04/11 3:39 AM, cyboman wrote:
i need to run an executable from vim. the problem that i'm facing is
that directory names in the path to this file contain spaces and vim
doesn't recognize that.

here is the problem
C:\Documents and Settings\myhomedirectory\someotherdirectory
\executable.exe

when i execute from vim
!C:\\Documents\ and\ Settings\\myhomedirectory\\someotherdirectory\
\executable.exe

i get the following message

C:\\Documents

I wonder what happened to the rest of the message.

Anyway...

I think it's because Vim basically passes the commandline to cmd.exe
which doesn't understand backslash escapes. Try enclosing in double
quotes instead.

!"C:\\Documents and Settings\\home\\otherdir\\executable.exe"

Not sure about doubling the backslashes, but I think it's
'optional'--but maybe it would work better without, so if the above
doesn't work, maybe try single backslashes.

Ben.




--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

cyboman
In reply to this post by Ben Schmidt
thanks for the help

On Thu, Apr 28, 2011 at 4:07 AM, Ben Schmidt <[hidden email]> wrote:
One of the ways to avoid spaces in Windows names of files and
directories is to replace any "controversial" names by their 8.3
equivalents

Of course, this will only work on filesystems that still support 8.3
equivalents and have that functionality turned on, which isn't always
the case these days. Just a potential gotcha with that approach.

Ben.




--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Jan Larres
In reply to this post by Ben Schmidt
Ben Schmidt <[hidden email]>:
>> One of the ways to avoid spaces in Windows names of files and
>> directories is to replace any "controversial" names by their 8.3
>> equivalents
>
> Of course, this will only work on filesystems that still support 8.3
> equivalents and have that functionality turned on, which isn't always
> the case these days. Just a potential gotcha with that approach.

Really? Ugh. I'm using this method for my 'Tagbar' plugin to call ctags
(using system()) since shellescape() doesn't seem to work in Windows for
this case. Could you give some information about when this might be the
case?

Thanks,
Jan

--
-[ OpenPGP key ID: 00A0FD5F ]-
There is no pleasure in having nothing to do; the fun is in having lots to
do and not doing it.
                -- Mary Wilson Little

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Ben Schmidt
On 29/04/11 8:51 PM, Jan Larres wrote:

> Ben Schmidt<[hidden email]>:
>>> One of the ways to avoid spaces in Windows names of files and
>>> directories is to replace any "controversial" names by their 8.3
>>> equivalents
>>
>> Of course, this will only work on filesystems that still support 8.3
>> equivalents and have that functionality turned on, which isn't always
>> the case these days. Just a potential gotcha with that approach.
>
> Really? Ugh. I'm using this method for my 'Tagbar' plugin to call ctags
> (using system()) since shellescape() doesn't seem to work in Windows for
> this case. Could you give some information about when this might be the
> case?

 From what I can gather from a little Googling:

- 8.3 filenames can only be disabled at all on NTFS volumes.
- They can be disabled system-wide from Windows NT onwards.
- They can be disabled per-volume on Windows 7.
- They are disabled by default on Windows (Server) 2008.

Ben.



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Jan Larres
Ben Schmidt <[hidden email]>:

> On 29/04/11 8:51 PM, Jan Larres wrote:
>>Ben Schmidt<[hidden email]>:
>>>>One of the ways to avoid spaces in Windows names of files and
>>>>directories is to replace any "controversial" names by their 8.3
>>>>equivalents
>>>
>>>Of course, this will only work on filesystems that still support 8.3
>>>equivalents and have that functionality turned on, which isn't always
>>>the case these days. Just a potential gotcha with that approach.
>>
>>Really? Ugh. I'm using this method for my 'Tagbar' plugin to call ctags
>>(using system()) since shellescape() doesn't seem to work in Windows for
>>this case. Could you give some information about when this might be the
>>case?
>
> From what I can gather from a little Googling:
>
> - 8.3 filenames can only be disabled at all on NTFS volumes.
> - They can be disabled system-wide from Windows NT onwards.
> - They can be disabled per-volume on Windows 7.
> - They are disabled by default on Windows (Server) 2008.

Thanks! I didn't expect you to Google it for me, though, I just thought
you already knew some details :)

Now to find some other workaround ...

Jan

--
-[ OpenPGP key ID: 00A0FD5F ]-
Fashion is a form of ugliness so intolerable that we have to alter it every
six months.
                -- Oscar Wilde

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: execute command from vim in windows

Jan Larres
Jan Larres <[hidden email]>:

>>> Ben Schmidt<[hidden email]>:
>>>>> One of the ways to avoid spaces in Windows names of files and
>>>>> directories is to replace any "controversial" names by their 8.3
>>>>> equivalents
>>>>
>>>> Of course, this will only work on filesystems that still support
>>>> 8.3 equivalents and have that functionality turned on, which isn't
>>>> always the case these days. Just a potential gotcha with that
>>>> approach.
>
> Now to find some other workaround ...

Just for the record, this seems to work for me in all the cases I tested
without the 8.3 workaround (partially based on the discussion at
http://vim.1045645.n5.nabble.com/bad-default-shellxquote-in-Widows-td1208284.html ):


  if exists('+shellslash')
      let shellslash_save = &shellslash
      set noshellslash
  endif

  let mycmd = shellescape(mybinary) . ' ' .  myargs . ' ' . shellescape(myfilename)

  if &shell =~ 'cmd\.exe'
      let shellxquote_save = &shellxquote
      set shellxquote=\"
      let shellcmdflag_save = &shellcmdflag
      set shellcmdflag=/s\ /c
  endif

  let output = system(mycmd)

  if &shell =~ 'cmd\.exe'
      let &shellxquote  = shellxquote_save
      let &shellcmdflag = shellcmdflag_save
  endif

  if exists('+shellslash')
      let &shellslash = shellslash_save
  endif


Jan

--
-[ OpenPGP key ID: 00A0FD5F ]-
The major problems in the world are the result of the difference between how
nature works and the way people think.
                -- Gregory Bateson

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php