Subject: Re: AW: how to use emacs in -batch mode from bash?
From: Christopher Faylor <[email-masked]>
To: Andrew Innes <[email-masked]>, [email-masked]
Cc: [email-masked], [email-masked], [email-masked], [email-masked]
Date: Wed, 17 Feb 1999 16:24:23 -0500

On Wed, Feb 17, 1999 at 07:09:28PM +0000, Andrew Innes wrote:
>However, we are now seeing the same problem occuring, this time on the
>Cygnus side.  The Cygnus port of bash will be applying the normal shell
>quoting rules to parse the command line typed by the user (or entered in
>the shell script), to construct the list of arguments to pass to Emacs.
>However, when bash invokes spawn() or exec() or some similiar library
>function to actually invoke Emacs, it has to flatten the argument list
>into a single string.  Clearly, the library function that does that is
>assuming the subprocess will use the Cygnus quoting rules to reconstruct
>the list of arguments.  That fails when an argument contains an embedded
>quote and the application doesn't use the Cygnus rules, which is the
>situation here.

As far as I know, the method used to "quote a quote" in cygwin is the
same as what is used in Visual C's libraries.  Here's a small program
that I just wrote to test this:

#include <stdio.h>
main(int argc, char **argv)
{
    int i;
    for (i = 0; i < argc; i++)
        printf("arg %d: /%s/\n", i, argv[i]);
}

And, here's the result:

c:\tmp>echoarg a b """"
arg 0: /echoarg/
arg 1: /a/
arg 2: /b/
arg 3: /"/

>Note that this is a problem with bash that applies when it invokes any
>application not compiled with the cygwin library, not just Emacs.
>
>I see two possible solutions to this general problem:
>
> 1. Change the cygwin spawn/exec/whatever library functions to use the
>    Microsoft rules for escaping embedded quotes when running non-cygwin
>    applications (I believe they already detects when they are spawning
>    non-cygwin applications; if not, the method Emacs uses could be
>    reused for this).

Cygwin does not know when it is running a non-cygwin application.  If it
did we wouldn't go through this quoting mess at all.

If Emacs is detecting this somehow, I'd love to hear how they do it.  I've
wanted to put more smarts into spawn for some time.

> 2. Change the cygwin quoting rules to match the Microsoft ones.  This
>    would apply to spawn/exec and the startup code, and would cause some
>    breakage when mixing with applications compiled with old versions of
>    cygwin.

See above.  As far as I can tell, cygwin is already compliant with Microsoft's
rules.  That was the intent in this whole scheme, actually.

>PS. There is a certain amount of irony in all this: the Microsoft
>startup code looks like it was intended to support escaping embedded
>quotes by doubling them (as Cygnus does), but the parsing code contains
>a bug which prevents this from working.  If not for this bug, the
>problem with bash invoking non-cygwin applications wouldn't arise.

I'm not sure why you're seeing this and I'm not but for my version of
MSVC 5.0 this seems to be working correctly.

cgf

--
Want to unsubscribe from this list?
Send a message to [email-masked]