[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new module 'system-quote'

From: Eli Zaretskii
Subject: Re: new module 'system-quote'
Date: Fri, 11 May 2012 08:24:33 +0300

> From: Bruno Haible <address@hidden>
> Cc: address@hidden
> Date: Fri, 11 May 2012 01:58:02 +0200
> > If I'm not missing anything, I submit that '*' should be removed from
> > the list of special characters.  Leaving it there means that it will
> > be impossible to invoke programs with arguments that include
> > wildcards.
> As far as I got it, on Windows XP, when a program calls another one,
> through CreateProcess() or cmd.exe, wildcard expansion will take place if
>   - the caller does not put double-quotes around the arguments, AND
>   - the callee uses argv[] rather than GetCommandLine() and, if it's
>     a mings program, does not define _CRT_glob to 0.

Correct, AFAIK.

> In other words, the caller has a way to avoid the wildcard expansion
> (through quoting), and the callee also has a way to avoid the wildcard
> expansion (by using GetCommandLine() and ignoring argv[]).

If the context of gnulib is to support Posix semantics as much as
possible, then the latter way should strictly speaking be out of
scope in this discussion.  But I don't think this is important for the
purposes of the point of this exchange.

> In gnulib, we try to make programs behave like described in POSIX, even
> on Windows. A POSIX program that does *not* want wildcard expansion
> will call one of system(), popen(), posix_spawn(), or use one of the
> modules 'execute', 'spawn-pipe'. A POSIX program that does want wildcard
> expansion will call glob() before calling system(), popen(), etc.
> So the right thing to do in gnulib is to avoid wildcard expansion, through
> quoting of '*' and '?'.

If programs need to call 'glob' before calling 'system' and 'popen'
with arguments quoted by this module, that fact should be prominently
mentioned in the documentation.  That's because there's nothing wrong
or non-Posixy in passing unquoted wildcard characters to 'system' or
'popen', as their command argument is known to be processed by a
shell.  (By contrast, 'spawn' and 'exec' families, and their
derivatives, are a different story: they don't--or, rather, shouldn't,
since Windows has its quirks here as well--need any quoting at all, no
matter what weird characters appear there.)  A Posix program that
calls 'system' with a string that includes unquoted wildcards _will_
get them globbed, and that is entirely OK.  So without proper
documentation, J. R. Hacker might be surprised to find herself unable
to pass arguments that include, say, both whitespace and wildcards.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]