From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32961 invoked by alias); 30 Aug 2019 19:16:38 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 32954 invoked by uid 89); 30 Aug 2019 19:16:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=reverses, UD:htm, Stephen X-HELO: NAM02-SN1-obe.outbound.protection.outlook.com Received: from mail-eopbgr770131.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) (40.107.77.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2019 19:16:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kdhv4KpwFBMqB1vgLy+GRl820ArbxkNTd5yb73LZ8ZyUR6UcX+3nUdV0gHKFKetMWlSSNlbaTXSLhvBGo+TZBiX0pazVTLUjj5kngxl2M7zaV3GLb4ZulaLVPY+5gbx4uqb2oD5eLji16CWNLRYlo+CxaTXXwTdt0u2KsGHApDVuBUaSMV4I9zF2ycXsfF9s4F1zFCP6Y8RDrhTYnA8CqFWJfJScukg1JNww6sbptoACGz2IU9u8sEYA56r6Vb+Eq8l2/AhZaMFUQH45K1UvWOQ933JcV2nPlM8/ptXI2GsKp37oXLznbMkHPWMbQ1HuTtKbWUEtSre3QGwMLRAcdg== 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-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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7z7kbSTGIuxjV+SU5zJReWOqFpd8lWbtRNPXULNalFE=; b=NiAEf+rhOoHA5a/3A8t0ix3rzvAHhEgqvwA+Knkcu1NmiImk6Ms/mS/Un3XrUOzjAbfcDo/2dWDNIVnJQsZKEX9un+LYrMuUT32OBxOLotzIFrtgXRI+CWeJM4dKV6BS7IwZJ2UvXTqDaz3znU1GBpedfcoURt1uQ1zOkkYLWOI= Received: from MWHPR21MB0845.namprd21.prod.outlook.com (10.173.51.139) by MWHPR21MB0144.namprd21.prod.outlook.com (10.173.52.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2241.3; Fri, 30 Aug 2019 19:16:33 +0000 Received: from MWHPR21MB0845.namprd21.prod.outlook.com ([fe80::3085:a037:7cbc:be5]) by MWHPR21MB0845.namprd21.prod.outlook.com ([fe80::3085:a037:7cbc:be5%5]) with mapi id 15.20.2241.000; Fri, 30 Aug 2019 19:16:33 +0000 From: "Stephen Provine via cygwin" Reply-To: Stephen Provine To: "cygwin@cygwin.com" Subject: Command line processing in dcrt0.cc does not match Microsoft parsing rules Date: Fri, 30 Aug 2019 19:31:00 -0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=stephpr@microsoft.com; x-ms-exchange-purlcount: 4 x-ms-oob-tlc-oobclassifiers: OLM:8882; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: P/TbxEGwCWwM65GvhqJ0102VkY2gZLoZ5A/X+0RjImOatD4TitpXgWWGfyyxlDVqpo5Iic2fwQJRU79i9h0ZTA== X-SW-Source: 2019-08/txt/msg00431.txt.bz2 The standard rules for Microsoft command line processing are documented her= e: https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=3Dvs.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 l= ine, and don't have control over how the command line string is generated f= rom 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 repla= cement for the CommandLineToArgv function in shell32.dll: https://github.com/golang/go/commit/39c8d2b7faed06b0e91a1ad7906231f53aa= b45d1 The behavior here is based on a detailed analysis of what command line pars= ing "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