[PATCH] Fix parameter passing containing quote/equal to Windows batch command

Max Polk maxpolk@gmail.com
Tue Jan 21 00:30:00 GMT 2014


On 1/20/2014 1:02 AM, Daniel Dai wrote:
> We notice one issue when running a Windows batch command inside
> cygwin. Here is one example.
>
> Simple batch file:
> a.bat:
> echo %1
>
> Run it under cygwin:
> ./a.bat a=b
> a
>
> ./a.bat "a=b"
> a
>
> If we pass additional \"
> ./a.bat "\"a=b\""
> "\"a
>
> There seems no way to pass a=b into bat.

This is how batch files work, and likely not a problem with Cygwin:
http://support.microsoft.com/kb/35938
Excerpt: "it is not possible to include an equal sign as an argument to 
a batch file"

Be careful to note that cmd.exe and .bat files naturally split a=b into 
two arguments and strip out the equals sign:

(Run from cmd.exe)
C:\>Argecho.bat a=b
FIRST a
SECOND b
THIRD

I did notice that adding double quotes (in cmd.exe) will make will it 
arrive as one argument, and note that the double quotes are still there:

(Run from cmd.exe)
C:\>Argecho.bat "a=b"
FIRST "a=b"
SECOND
THIRD

There is a problem getting Cygwin the above test case, however.

The test script was:
C:\>type Argecho.bat
@echo off
echo FIRST %1
echo SECOND %2
echo THIRD %3

When run from Cygwin bash, and you force the double quotes by 
surrounding double quotes "a=b" with single quotes '"a=b"', you seem to 
get too *many* quotes in the batch file:

(Run from bash, the batch file behaves correctly as if run from cmd.exe)
$ Argecho.bat a=b
FIRST a
SECOND b
THIRD

(Run from bash, same as above since bash removes the double quotes prior 
to passing to program):
$ Argecho.bat "a=b"
FIRST a
SECOND b
THIRD

(Run from bash, this is what is surprising double surrounded with single)
$ Argecho.bat '"a=b"'
FIRST "\"a
SECOND b\""
THIRD

It seems that only the final test case above doesn't behave as expected.



More information about the Cygwin-patches mailing list