[Top][All Lists]

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

Re: new module 'system-quote'

From: Bruno Haible
Subject: Re: new module 'system-quote'
Date: Fri, 11 May 2012 01:58:02 +0200
User-agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; )

Hi Eli,

> > If you want to see what happens, just remove the '*' from
> > SHELL_SPECIAL_CHARS and re-run the unit test.
> I see this:
>   for input = |*|: CreateProcess() command failed with status 3: 
> .\test-system-quote-child.exe *
> But IIUC that just means we hit this condition in the child:
>   if (argc > 2)
>     /* Expected one data argument, received more than one.  */
>     return 3;

Oops, you're absolutely right. I had not looked precisely where the code 3
came from.

Thanks for explaining. It wasn't clear to me that on native Windows,
it's generally the callee which performs wildcard expansion. I have now
fixed the comments accordingly.

> 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.

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[]).

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 '?'.


reply via email to

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