This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Command line processing in dcrt0.cc does not match Microsoft parsing rules
- From: "Stephen Provine via cygwin" <cygwin at cygwin dot com>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Fri, 30 Aug 2019 19:16:33 +0000
- Subject: Command line processing in dcrt0.cc does not match Microsoft parsing rules
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7z7kbSTGIuxjV+SU5zJReWOqFpd8lWbtRNPXULNalFE=; b=U7rTwcqgA4BUe8l1vC9F+Vx6T9lQmYgsZAE/ZDupgy94U7nFEzs5WKhidl0Ml6mb3xTq7KKVr5DJclpGFPIceFddVIa/osc260d7lRanwJMgz/38MLiflAsa4QBcq9GxehUm9Cre+7npmcossQHsi+Lmk1sa4CpiizdK0qYMJT5QOUb41PjgrmO42fR41U5mgSyOigSq83DG+Xm1FEFvB6MhK3rAGZ2KNKX4+Gw/moDhONpNB++JzMFVuypgQnidtHns6l5ZEyjuE+dxHGMuOnHqg5VPQwD/Zp/+cOhxBMHeuAymV8Wtzc/IVYkrBeZdD/JRkc+k1t863xMBQy0TBA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kdhv4KpwFBMqB1vgLy+GRl820ArbxkNTd5yb73LZ8ZyUR6UcX+3nUdV0gHKFKetMWlSSNlbaTXSLhvBGo+TZBiX0pazVTLUjj5kngxl2M7zaV3GLb4ZulaLVPY+5gbx4uqb2oD5eLji16CWNLRYlo+CxaTXXwTdt0u2KsGHApDVuBUaSMV4I9zF2ycXsfF9s4F1zFCP6Y8RDrhTYnA8CqFWJfJScukg1JNww6sbptoACGz2IU9u8sEYA56r6Vb+Eq8l2/AhZaMFUQH45K1UvWOQ933JcV2nPlM8/ptXI2GsKp37oXLznbMkHPWMbQ1HuTtKbWUEtSre3QGwMLRAcdg==
- Reply-to: Stephen Provine <stephpr at microsoft dot com>
The standard rules for Microsoft command line processing are documented here:
https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85)
The Cygwin code for command line processing is in dcrt0.cc, function build_argv.
The behaviors do not match. For instance, given a test.sh script like this:
#!/bin/bash
echo $1
And the following invocation of bash.exe from a Windows command prompt:
bash.exe test.sh foo\"bar
The result is:
foo\bar
When the expected result is:
foo"bar
As a workaround, you can achieve the expected result using:
bash.exe test.sh "foo\"bar"
Which is great until you use a language like Go to shell exec the command line, and don't have control over how the command line string is generated from an original set of arguments. See:
https://github.com/golang/go/blob/master/src/syscall/exec_windows.go#L86
Go just reverses the Microsoft standard rules in the most efficient manner possible, but those command lines don't parse correctly in Cygwin processes.
Go implements a pretty definitive command line parsing algorithm as a replacement for the CommandLineToArgv function in shell32.dll:
https://github.com/golang/go/commit/39c8d2b7faed06b0e91a1ad7906231f53aab45d1
The behavior here is based on a detailed analysis of what command line parsing "should" be in Windows:
http://daviddeley.com/autohotkey/parameters/parameters.htm#WINARGV
It would be very nice if Cygwin followed the same procedure at startup.
Thanks,
Stephen
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple