public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes
@ 2011-03-18 18:45 Alex Khripin
  2011-03-18 22:07 ` Larry Hall (Cygwin)
  0 siblings, 1 reply; 6+ messages in thread
From: Alex Khripin @ 2011-03-18 18:45 UTC (permalink / raw)
  To: cygwin

Hi,

Short summary: getting nested quotes in an argument through to a
Cygwin process from DOS is problematic, and there does not seem to be
any detailed spec for how to escape quotes correctly. Backslash
characters seem to be spuriously generated.

I'm working on a build system (GNU make, Windows build), which invokes
the Cygwin shell to run commands, like so:
sh.exe -c "command arg1 arg2 etc"

I've run into some serious problems when command is a DOS path (e.g.
c:/qtpath/moc.exe) and one of the arg's is quoted.

Naturally, the problem could be at two points:
1) the Windows code in make could be escaping things incorrectly for
the Cygwin loader to interpret
2) the Cygwin loader does not handle this case correctly.

************ A simple test **************
I made the following simple Cygwin program, to better show what sh.exe
would be getting from make:
#include <stdio.h>
int main(int argc, char **argv) {
    int i;
    for (i = 1; i < argc; i++) printf("%d : %s\n", i, argv[i]);
    return 0;
}

------ Normal program name ------
c:\cygwin\home\akhripin>args "foo 1 ""2 3"" 4"
1 : foo 1 "2 3" 4
------ DOS'y program name ------
c:\cygwin\home\akhripin>args "c:/foo 1 ""2 3"" 4"
1 : c:/foo 1 \2 3\ 4

As you can see, the second case causes \ escape characters to show up
- and the worst thing, one of them is now escaping a space - so the
above would be further split up as c:/foo 1 2 "3 4" -- completely
changing which arguments were grouped together.

************ The noglob option **************
When I turn on CYGWIN=noglob, there seems to be no way at all to get a
double quote through to the test program - no amount of escaping or
single quotes does the trick. As such, that does not seem to be an
option available to me.

************ Is the above a bug? **************
I cannot find any mailing list entries or documentation on how quotes
are processed. I looked at the cygwin source (winsup/sources/dcrt0.cc)
and it looks like it enables special processing when an argument
starts with Letter-Colon. I'm sure that's there for good reasons - but
is that processing correct for cases with quotes?

Basically, my question boils down to: is this a Cygwin problem that
can be fixed, or should I pursue a fix to Windows make?

************ Correct escaping **************
From what I've been able to determine, there is no consistent way to
escape " and \ characters that works both for arguments that are
"normal" and those that look like DOS paths. If that is the intent,
that's fine - I've been working on a patch for make.

My conclusion is that for escaping normal arguments, the current
approach of turning nested " into "" and \ into \\ works fine.

For arguments that look like DOS paths, it looks like the right answer
is pretty complex: enclose the whole argument in " if it is not, then
use "'"'" for " and "\" for \; what this does is close the current
double quoted statement, insert the desired character, and resume the
double quoted statement

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes
  2011-03-18 18:45 Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes Alex Khripin
@ 2011-03-18 22:07 ` Larry Hall (Cygwin)
  2011-03-19  5:10   ` David Boyce
  2011-03-20 22:22   ` Buchbinder, Barry (NIH/NIAID) [E]
  0 siblings, 2 replies; 6+ messages in thread
From: Larry Hall (Cygwin) @ 2011-03-18 22:07 UTC (permalink / raw)
  To: cygwin

On 3/18/2011 2:39 PM, Alex Khripin wrote:
> Hi,
>
> Short summary: getting nested quotes in an argument through to a
> Cygwin process from DOS is problematic, and there does not seem to be
> any detailed spec for how to escape quotes correctly. Backslash
> characters seem to be spuriously generated.

If you're using a native Windows 'make' with a Cywgin shell, you're better
off making your tools consistent.  Quoting mechanisms for Windows do not
align with those used by Cygwin/Linux/Unix, so things are already problematic.
Passing in a DOS path to a Cygwin shell and expecting the output to be
properly quoted for a Windows version of 'make' is just asking for trouble.
So I'd recommend staying on one side of the fence or the other if you want
to minimize headaches.

-- 
Larry

_____________________________________________________________________

A: Yes.
> Q: Are you sure?
>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top posting annoying in email?

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes
  2011-03-18 22:07 ` Larry Hall (Cygwin)
@ 2011-03-19  5:10   ` David Boyce
  2011-03-19  6:24     ` Charles Wilson
  2011-03-19  6:32     ` Christopher Faylor
  2011-03-20 22:22   ` Buchbinder, Barry (NIH/NIAID) [E]
  1 sibling, 2 replies; 6+ messages in thread
From: David Boyce @ 2011-03-19  5:10 UTC (permalink / raw)
  To: cygwin

On Fri, Mar 18, 2011 at 6:00 PM, Larry Hall (Cygwin) wrote:
> On 3/18/2011 2:39 PM, Alex Khripin wrote:
> If you're using a native Windows 'make' with a Cywgin shell, you're better
> off making your tools consistent.  Quoting mechanisms for Windows do not
> align with those used by Cygwin/Linux/Unix, so things are already
> problematic.
> Passing in a DOS path to a Cygwin shell and expecting the output to be
> properly quoted for a Windows version of 'make' is just asking for trouble.
> So I'd recommend staying on one side of the fence or the other if you want
> to minimize headaches.

That's the expected - and generally reasonable - answer from the
Cygwin side, but it's worth noting that GNU make documents this combo
as being workable. From the README.W32 file in the source package:

       Good news! Make now has native support for Cygwin sh. To enable,
       define the HAVE_CYGWIN_SHELL in config.h and rebuild make
       from scratch. This version of make tested with B20.1 of Cygwin.
       Do not define BATCH_MODE_ONLY_SHELL if you use HAVE_CYGWIN_SHELL.

-dsb

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes
  2011-03-19  5:10   ` David Boyce
@ 2011-03-19  6:24     ` Charles Wilson
  2011-03-19  6:32     ` Christopher Faylor
  1 sibling, 0 replies; 6+ messages in thread
From: Charles Wilson @ 2011-03-19  6:24 UTC (permalink / raw)
  To: cygwin

On 3/18/2011 11:47 PM, David Boyce wrote:
> From the README.W32 file in the source package:
> 
>        Good news! Make now has native support for Cygwin sh. To enable,
>        define the HAVE_CYGWIN_SHELL in config.h and rebuild make
>        from scratch. This version of make tested with B20.1 of Cygwin.

Wow.  I suspect bit rot, as B20.1 dates back to 1998:
http://cygwin.com/ml/cygwin/1998-12/msg00093.html

Any path conversion that this specially-configured make might do, in
order to turn its native DOS-ish paths into something CYGWIN_SHELL might
understand, is probably (a) a crude heuristic that no longer applies,
(b) uses now-deprecated functions, or (c) relies on explicitly calling
system("cygpath ....") on every PATH, every time a shell command is
invoked (yikes).

--
Chuck



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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes
  2011-03-19  5:10   ` David Boyce
  2011-03-19  6:24     ` Charles Wilson
@ 2011-03-19  6:32     ` Christopher Faylor
  1 sibling, 0 replies; 6+ messages in thread
From: Christopher Faylor @ 2011-03-19  6:32 UTC (permalink / raw)
  To: cygwin

On Fri, Mar 18, 2011 at 11:47:12PM -0400, David Boyce wrote:
>On Fri, Mar 18, 2011 at 6:00 PM, Larry Hall (Cygwin) wrote:
>> On 3/18/2011 2:39 PM, Alex Khripin wrote:
>> If you're using a native Windows 'make' with a Cywgin shell, you're better
>> off making your tools consistent. ?Quoting mechanisms for Windows do not
>> align with those used by Cygwin/Linux/Unix, so things are already
>> problematic.
>> Passing in a DOS path to a Cygwin shell and expecting the output to be
>> properly quoted for a Windows version of 'make' is just asking for trouble.
>> So I'd recommend staying on one side of the fence or the other if you want
>> to minimize headaches.
>
>That's the expected - and generally reasonable - answer from the
>Cygwin side, but it's worth noting that GNU make documents this combo
>as being workable. From the README.W32 file in the source package:
>
>       Good news! Make now has native support for Cygwin sh. To enable,
>       define the HAVE_CYGWIN_SHELL in config.h and rebuild make
>       from scratch. This version of make tested with B20.1 of Cygwin.
>       Do not define BATCH_MODE_ONLY_SHELL if you use HAVE_CYGWIN_SHELL.

Even if it is supposed to be workable it's not a combination that's
supported here.

cgf

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes
  2011-03-18 22:07 ` Larry Hall (Cygwin)
  2011-03-19  5:10   ` David Boyce
@ 2011-03-20 22:22   ` Buchbinder, Barry (NIH/NIAID) [E]
  1 sibling, 0 replies; 6+ messages in thread
From: Buchbinder, Barry (NIH/NIAID) [E] @ 2011-03-20 22:22 UTC (permalink / raw)
  To: cygwin

Larry Hall (Cygwin) sent the following at Friday, March 18, 2011 6:01 PM
>On 3/18/2011 2:39 PM, Alex Khripin wrote:
>> Short summary: getting nested quotes in an argument through to a
>> Cygwin process from DOS is problematic, and there does not seem to beif you must
>> any detailed spec for how to escape quotes correctly. Backslash
>> characters seem to be spuriously generated.
>
>If you're using a native Windows 'make' with a Cygwin shell, you're
>better off making your tools consistent. Quoting mechanisms for Windows
>do not align with those used by Cygwin/Linux/Unix, so things are already
>problematic. Passing in a DOS path to a Cygwin shell and expecting the
>output to be properly quoted for a Windows version of 'make' is just
>asking for trouble. So I'd recommend staying on one side of the fence or
>the other if you want to minimize headaches.

I agree totally with Larry.  However, if you must use a mixed environment,
consider trying to get the commands into a script or batch file, convert
line endings appropriately, and then run the script with
  $ C:\cygwin\bin\bash -c script
or
  C:\> "$(cygpath -u "${COMSPEC}")" /c batch.bat

- Barry
  Disclaimer: Statements made herein are not made on behalf of NIAID.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-20 22:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-18 18:45 Cygwin (1.7.8 and other versions) problems with globbing when invoked from DOS/Windows with nested quotes Alex Khripin
2011-03-18 22:07 ` Larry Hall (Cygwin)
2011-03-19  5:10   ` David Boyce
2011-03-19  6:24     ` Charles Wilson
2011-03-19  6:32     ` Christopher Faylor
2011-03-20 22:22   ` Buchbinder, Barry (NIH/NIAID) [E]

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).