This is the mail archive of the cygwin-patches 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: [PATCH] Fix parameter passing containing quote/equal to Windows batch command


Thanks Václav!

You are right, I tried on exe file, things works fine on exe, but not
bat file. Seems some cleanup is done before we running into main
function of exe.

So how do we want to fix bat? The rules in my patch seems apply even for exe:
1. if parameter is already quoted, don't quote again
2. if parameter contains equal, quote it

It probably duplicate some logic with exe bootstrap code, but I don't
see any harm.

Another way to fix is to apply the rule only we see a bat file. That
should solve my problem as well.

Thanks,
Daniel





On Tue, Jan 21, 2014 at 4:31 AM, Václav Zeman <vhaisman@gmail.com> wrote:
> On 21 January 2014 01:30, Max Polk wrote:
>> 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.
>
> Beware! The way CMD.exe handles command line and parameters is
> different/incompatible from the way C (MSVCRT) application handles
> them. Do not confuse the two. You cannot prove/show anything about how
> C application handles arguments by using CMD.exe as a show case.
>
> --
> VZ


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