delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/10/13/16:25:22

X-Spam-Check-By: sourceware.org
Message-ID: <452FF616.4040205@cs.berkeley.edu>
Date: Fri, 13 Oct 2006 13:24:54 -0700
From: Johnathon Jamison <jjamison AT cs DOT berkeley DOT edu>
User-Agent: Thunderbird 1.5.0.7 (Windows/20060909)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Bash fails to run .bat file with spaces in pathname and argument
References: <31DDB7BE4BF41D4888D41709C476B6570416918D AT NIHCESMLBX5 DOT nih DOT gov>
In-Reply-To: <31DDB7BE4BF41D4888D41709C476B6570416918D@NIHCESMLBX5.nih.gov>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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

Buchbinder, Barry (NIH/NIAID) [E] wrote:
> 
> The problem is, at least in part, with cmd.  cmd /? says:
> 
>   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.
> 

This tells me that CreateProcess is not really at fault at all, but 
instead the fix is to create a different command line.  I can think of 
one of two things: (1) do not have a double quote as the first 
character, (2) if the program is quoted and there exists an argument 
quoted as well, replace ' ' with '^ ' everywhere in the program and add 
a '^' at the end of the program before the quote.

> Try using short names to get rid of the first set of quotes.  Short
> names still work, at least on XP.  Compare
>   c:\>dir docume~1
> and
>   c:\>dir "Documents and Settings"
> 
> To find out the short names,
>   c:\>dir /x
> Or one can guess (first 6 characters + "~" + "1", or a higher digit if
> the 6 characters + "~1" is already used, + "." + first 3 characters of
> the extension).
> 
> Try changing the batch file from
>   echo %1
> to
>   echo %1 %2 %3 %4 %5 %6 %7 %8 %9
> That should work by getting rid of the second set of quotes, at least if
> the number of arguments is less than 10.
> 
> This, also, works
> 
>   /c> echo '"c:\Documents and Settings\BBuchbinder\test.bat" "hello
> world"
>   exit' | u2d | cmd /k
>   c:\>"c:\Documents and Settings\BBuchbinder\test.bat" "hello world"
> 
>   c:\>echo "hello world"
>   "hello world"
> 
>   c:\>exit
> 
> You can leave off the "/k", but you then get extraneous text from
> cmd.exe as it loads.
> 

This is a lot of good info, especially since I generally do not use DOS. 
  Thank you.

Johnathon

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