Closed p5pRT closed 20 years ago
The README.win32 file in the perl distribution seems to indicate that the porter does not fully understand the rules of command line parsing on this platform\, so here is my explanation for your benefit.
The Win32 command shells *do not* parse the command line into arguments. With two exceptions noted below\, the command line is passed unedited and unparsed as a single NULL terminated string to perl.exe (or any other program). Quotes\, spaces\, wildcards etc. are simply forwarded to the application without any checking or enforcement of rules such as quote balancing.
This string is returned from the GetCommandLine(void) system call.
Thus the notion of UNIX-like argc/argv passed to main() is an effect of the C runtime library and may be overridden by simply providing your own implementation. If you can squeeze a call to your own implementation into perl's main()\, you don't even have to figure out how to get rid of the C compilers parser\, just ignore the results and provide your own.
Also note\, that most C compilers do come with source code for their command line parser.
The two exceptions are: 1. Redirection: The command shell parses for redirections and pipes and deletes the associated characters from the command line. 2. Choice of executable: The command shell interprets the first (possibly quoted) argument as the program to be located in the path\, but does not delete it from the command line.
Neither of these two exceptions apply to the CreateProcess system call.
Hope this helps you make an even better Win32 port of perl.
While trying to clear out some ancient cruft from the bug database\, I found this message from Jacob Bo/hm: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-08/msg00098.html
I have no idea whether his assertions about win32 command-line parsing are correct\, but the information does not appear to have changed in 5.6.0 (looking at the paragraph that starts 'The crucial thing to understand about the "cmd" shell'). Can someone that knows clarify?
Hugo
I have no idea whether his assertions about win32 command-line parsing are correct
They look mostly correct to me\, but I've never tried to figure out what happens to %environment% references\, and there are still rules that cmd.exe uses for things like quoting and escaping because it has to parse the line to find the redirection characters (thus leaving exciting areas for the application to parse things differently than the shell :-).
On Thu\, 13 Jul 2000 17:13:39 BST\, Hugo wrote:
While trying to clear out some ancient cruft from the bug database\, I found this message from Jacob Bo/hm: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-08/msg00098.html
I have no idea whether his assertions about win32 command-line parsing are correct\,
They're correct\, but he's talking about it from the POV of the low-level Win32 API. Perl uses the CRT's argv/argc abstraction that is built (precariously) on top that low level support\, so describing the lower level is not much good to the end user.
but the information does not appear to have changed in 5.6.0 (looking at the paragraph that starts 'The crucial thing to understand about the "cmd" shell'). Can someone that knows clarify?
I don't see anything that needs changing there.
However\, we do need to fix various amounts of brokenness that prevent system(@args) from working right on windows. Search archives for "spawnvp" if you're interested in pursuing this.
Sarathy gsar@ActiveState.com
In \200007131720\.KAA12643@​molotok\.activestate\.com\, Gurusamy Sarathy writes: :On Thu\, 13 Jul 2000 17:13:39 BST\, Hugo wrote: :>While trying to clear out some ancient cruft from the bug database\, :>I found this message from Jacob Bo/hm: :> http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/1999-08/msg00098.htm :l :> :>I have no idea whether his assertions about win32 command-line parsing :>are correct\, : :They're correct\, but he's talking about it from the POV of the low-level :Win32 API. Perl uses the CRT's argv/argc abstraction that is built :(precariously) on top that low level support\, so describing the lower :level is not much good to the end user. : :>but the information does not appear to have changed in :>5.6.0 (looking at the paragraph that starts 'The crucial thing to :>understand about the "cmd" shell'). Can someone that knows clarify? : :I don't see anything that needs changing there.
Ok\, I'll mark the bugid closed.
Hugo
From: Gurusamy Sarathy [mailto:gsar@ActiveState.com]
They're correct\, but he's talking about it from the POV of the low-level Win32 API. Perl uses the CRT's argv/argc abstraction that is built (precariously) on top that low level support\, so describing the lower level is not much good to the end user.
but the information does not appear to have changed in 5.6.0 (looking at the paragraph that starts 'The crucial thing to understand about the "cmd" shell'). Can someone that knows clarify?
I don't see anything that needs changing there.
I could argue that the user needs to know that there are two forces at work - the command shell (which may be CMD\, but may also be something like 4NT\, or even something obscure like zsh) and the CRT argc/argv implementation that Perl uses.
A particular gotcha with the 4NT shell is that if you fail to double % characters\, even when quoted\, they get eaten by the environment variable expansion process. This is not a problem with CMD.
I don't think it's README.win32's place to document the idiosyncracies of all the various Windows shells which could be used (any more than we do for Unix)\, but it probably *is* worth explaining that the shell and the CRT are both involved.
Does the attached patch explain things any better?
[BTW\, note that I changed the comment about quoting redirection characters - based on my experiments\, it *does* work\, at least in CMD.EXE]
Paul.
---- Patch for perlwin32.pod ----
Does the attached patch explain things any better?
[BTW\, note that I changed the comment about quoting redirection characters - based on my experiments\, it *does* work\, at least in CMD.EXE]
Applied\, thanks.
Migrated from rt.perl.org#1151 (status was 'resolved')
Searchable as RT1151$