Post by Julien LecomteI believe that mingw-runtime should trim the spaces on the right
before calling WinMain and that results should be more consistent
under cmd.exe. Should we or not modify mingw-runtime to trim
those spaces?
I believe this is more likely to be an issue with the way in which
MSYS' sh.exe reconstructs the command line it passes to the child
process, rather than a problem in mingw-runtime.
Any native Woe32 process receives its arguments as a single string
of characters. Whatever you type on the cmd.exe command line just
gets passed verbatim to the child; this includes any leading or
trailing spaces which happen to be present, after the command name
has been carved off, and up to any following command separator. The
only exception to this is that redirection operators are actioned,
and filtered out.
MSYS' sh.exe, OTOH, behaves like any UNIX shell. It parses each
command line, expanding one level of quoting, and constructs an
argument vector; this is then passed to the child through an `exec'
function call, (after forking a process in which to run the child).
To make this work in the Woe32 world, MSYS' `exec' function has to
reconstruct a single command line argument string, from the passed
argument vector; it is this reconstructed string which is then
passed to the child, via the system's own `CreateProcess' function.
I don't think it would be practical to make sh.exe reproduce the
behaviour of cmd.exe, wrt redundant white space; here are just a
few of the reasons which spring to mind:
1) While constructing the argument vector for `exec', one level of
quoting is expanded; the quoting characters are discarded.
2) In this process, all unquoted white space is discarded.
3) Attempting to modify this behaviour would, in all likelihood,
destroy sh.exe's variable expansion and command substitution
features.
4) sh.exe supports a much richer set of quoting capabilities; it
is not practical to simply pass all quoting directly to a Woe32
process, which is unlikely to understand the syntax.
One thing which does seem odd, is the single trailing space left on
the *unquoted* argument in your example; I would not have expected
the MSYS `exec' function to add that, so it could be considered a
bug, which we may wish to investigate. Please raise a ticket on
the bug tracker:
https://sourceforge.net/tracker/?func=add&group_id=2435&atid=102435
FWIW, you should also note that Woe32's own `exec' function, as
provided by MSVCRT, is critically broken wrt the quoting of grouped
arguments with included white space, which are present in the passed
argument vector. The disfunctional `spawn' functions, which MSVCRT
provides instead of the `fork()...exec()' API is identically broken.
For an explanation, and GPLed workaround, see:
https://sourceforge.net/project/showfiles.php?group_id=2435&package_id=82725&release_id=366538
Regards,
Keith.