delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/08/08/14:58:53

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Fri, 8 Aug 2008 13:58:12 -0500 (CDT)
From: Tim McDaniel <tmcd AT panix DOT com>
cc: cygwin AT cygwin DOT com
Subject: Re: Bizarre Cygwin/Explorer/paths problem half-solved
In-Reply-To: <ba40711f0808081039n5d6cded1sa0744d8ab4b0c088@mail.gmail.com>
Message-ID: <Pine.NEB.4.64.0808081315200.7241@panix1.panix.com>
References: <20080808064144 DOT 94C9485E51 AT pessard DOT research DOT canon DOT com DOT au> <Pine DOT NEB DOT 4 DOT 64 DOT 0808081010250 DOT 2416 AT panix1 DOT panix DOT com> <20080808162840 DOT GA31347 AT ednor DOT casa DOT cgf DOT cx> <ba40711f0808081039n5d6cded1sa0744d8ab4b0c088 AT mail DOT gmail DOT com>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Fri, 8 Aug 2008, Lev Bishop <lev DOT bishop AT gmail DOT com> wrote:
> On Fri, Aug 8, 2008 at 12:28, Christopher Faylor  wrote:
>
>>> Is there any documentation on who rewrites arguments, under what
>>> conditions, and how they're altered?
>>
>> I missed this when it was first mentioned.

I've skipped parts of this thread, so my reply here may well be
repeating something recently said.

>> Cygwin doesn't munge command line arguments.  Why would it assume
>> that /e,something was a windows path?  That makes no sense.
>
> Nobody is munging anything.
>
> What's going on here is as simple as the difference:
>
> bash-3.2$ cmd /c echo "a b c"
> "a b c"
> bash-3.2$ cmd /c echo a b c
> a b c
>
> There's really no more to it than that.

Actually, bash *does* munge arguments passed to Windows commands,
but by surrounding them with double quotes when invoking the commands,
not by translating paths.  To wit:

Except that on 4 Aug, Gary R. Van Sickle wrote:
>  # Easy "Explorer here" command with tree control on the left
>  x()
>  {
>  	if [ "${1}" = "" ];
>  	then
>  		# No parameter given, open Explorer in the current directory.
>  		XPATH=".";
>  	else
>  		# Open the given path.
>  		XPATH="$(cygpath -w "${1}")";
>  	fi
>  	explorer /e,$XPATH & disown %-
>  }

and Luke replied
> Don't try this variant, though, since it doesn't work:
>
>     explorer /e,"$XPATH" & disown %-
> 
> What happens if you try that innocuous-looking variant is that
> Cygwin (or bash?) normalises the path /e,... to a windows path
> first, producing \e,...

I used this function, to control the quoting and to avoid stomping on
/usr/bin/X11/x:

     # Source this file only.
     xx()
     {
          WHICH=explorer
          # WHICH=local/test/032.bat
          # WHICH="cmd /c $WHICH"
          if [[ $2 = "" ]];
          then
                  # No parameter given, open Explorer in the current directory.
                  XPATH=.;
          else
                  # Open the given path.
                  XPATH=$(cygpath -w "$2");
          fi
          if [[ $1 = quote ]]; then
              (set -x; $WHICH /e,"$XPATH") & disown %-
          else
              (set -x; $WHICH /e,$XPATH) & disown %-
          fi
     }

Luke is halfway correct: quoting $XPATH can make it fail, but
apparently not for the reason he thinks.  If xx is called as
     xx noquote '/Program Files'
(that is, avoiding quoting of $XPATH), it works, but
     xx quote '/Program Files'
results in a Windows Explorer error window saying
     The path '/e,C:\Program Files' does not exist or is not a
     directory.

Mucking about in a cmd window shows that
     explorer /e,C:\Program Files
gives the correct result while
     explorer "/e,C:\Program Files"
gives the same Windows Explorer error window as above.
And explorer insists on ",", not a space.  That all totally sucks.

(I was curious:
     explorer '/e,C:\Program Files'
gives the error box but saying that 'C:\Program Files' doesn't exist.)

Doing a simple test:

     #! /bin/bash
     XPATH='C:\Program Files'
     if [[ $1 = quote ]]; then
         (set -x; local/test/032.bat /e,"$XPATH") & disown %-
     else
         (set -x; local/test/032.bat /e,$XPATH) & disown %-
     fi

where 032.bat is

     @echo off
     echo in bat
     for %%f in (%*) do echo arg %%f

I find that, with /e,$XPATH, bash just passes it down as separate
arguments,
     arg /e
     arg C:\Program
     arg Files
but with /e,"$XPATH", bash actually passes a real double-quoted
string:
     arg "/e,C:\Program Files"
which explorer.exe refuses to accept because it's idiotic
as aforesaid.
     explorer /e,"C:\Program Files"
would work too, but I don't see how to get bash to generate it.

That's most unpleasant.  I don't suppose there's any way to control
Cygwin's bash in re where to put double quotes around arguments being
passed to a Windows command (since getting Microsoft to make
explorer.exe be sane is hopeless)?  Except by not using characters
that bash thinks need quoting.

I found two workarounds that have safe quoting of $XPATH:
     XPATH=$(cygpath -s -w "$2");  # produce the Windows short name
     ...
     cmd /c explorer /e,"$XPATH"
(that's the "not using characters that need quoting" path) or
     XPATH=$(cygpath -w "$2");
     ...
     cmd /c "explorer /e,$XPATH"

Again, my apologies if this has all been covered recently -- I was too
lazy to check the list archives as I should have.

-- 
Tim McDaniel, tmcd AT panix DOT com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019