This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bizarre Cygwin/Explorer/paths problem half-solved


On Fri, 8 Aug 2008, Lev Bishop <lev.bishop@gmail.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@panix.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]