X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:reply-to:to:subject:date:message-id :content-type:content-transfer-encoding:mime-version; q=dns; s= default; b=p/7+vbPVp4DMFLXzR3BzaFqoiumAkgjyjhspNO8GMLAcO/ileb03L mkXrWqdTi9FjXCslV7jX2V79dtaPozJuElTXYJfFfPZi02FIdl87yunU6tl5v2YY 3eZKwTh0IwRbC2tiLlWpSvIIclBEAMovQuqBUUUhYRKEcJxdhKVeWU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:reply-to:to:subject:date:message-id :content-type:content-transfer-encoding:mime-version; s=default; bh=dKF3c9WTOLGjYlpfwQWR4HqziDo=; b=cYKvdSmTiGjRztrO1UbnRrhMcu9k 41qVePtTadYA2sAaNmfZ/g6iXoBrYcpCPIDlp36ARb+YeMiSaySgDXAlsYR2fpyW no7w9uSpCwlX3LLJJsv1oHP9Pb6pgh5bMc5F7lAkray4/2q4U5HGnax2tsC1M+cI FH2xG6J69SiFucM= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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 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= From: "Stephen Provine via cygwin" Reply-To: Stephen Provine To: "cygwin AT cygwin DOT com" Subject: Command line processing in dcrt0.cc does not match Microsoft parsing rules Date: Fri, 30 Aug 2019 19:16:33 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=stephpr AT microsoft DOT 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" MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: P/TbxEGwCWwM65GvhqJ0102VkY2gZLoZ5A/X+0RjImOatD4TitpXgWWGfyyxlDVqpo5Iic2fwQJRU79i9h0ZTA== Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id x7UJHAn1025919 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