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:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=HJf hL2fJKX1/GTNYdykdEdDIHQzRDmc6r/KBNDTNdfhyPzGbx9KQlc74rfRt0SBBl4W ZeSqufWY4ce4P8BPiffZiUJP6xMtDYRKSHAXzrlQVivVWKUj9NNOU7eRqe+jUfRM esgkfALa8gNkPzQJvhwU0o6DIO+68T1wB2kHUqVY= 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:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; s=default; bh=p+fz7L1tz 2iploQnO3b1E89FZyY=; b=nagtXoV2WHrQpxuMWS0o6PINvnML5inUbk0Trr5QX zRSw3s4iMoaf8zuqEYyzSKp/wtPCyCUEkoLPOQaM5L6Ofa/QAjQcpOPPw50mtu+Y nTf5Nrz2gktGFyTpim0qkFWapc77CdTaCzCuCOvCFA9npX41gv+gip7fk4U76fWu uA= 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-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=BAYES_40,LIKELY_SPAM_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=H*UA:16.0, Hx-spam-relays-external:sk:mail.au, H*RU:sk:mail.au, H*r:sk:mail.au X-HELO: outmail149082.authsmtp.co.uk From: "David Allsopp" To: Subject: Formatting command line arguments when starting a Cygwin process from a native process Date: Thu, 5 May 2016 17:24:14 +0200 Message-ID: <005c01d1a6e2$30270ba0$907522e0$@metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Server-Quench: 6d7e1636-12d5-11e6-829e-00151795d556 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCd1ZAARAlZZVg1f DC4bFwdFRBksPQFF ChxFJgxfNlEYWhtQ NG5RP1VMMVtaTlZc TWYORCkFGUJzWWJz ewtXZwdZaEtLEQdr U1ZIQldMFgRqHx0A AgEcVwZzOUBCfQgP EAU+XnJSXkx9O0R5 QkoaEzkBMGZma2YC UUIMch5VcVZMYxdH YwViVHMMZGQAb380 QlJtKR42JzBWNDhU RA5FJlUXRE8NEnY4 RhYPVTw1ElAASiMv NFQ5KlMaVF0NO18u MF0uEVtQGA4dFQxY V1lXByRUPEJJSTAs CEtTFUgXDDxDTG9E GBojLwRTam4I X-Authentic-SMTP: 61633634383431.1037:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 213.105.212.114/25 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. I am trying to work out the precise details for character escaping when starting a Cygwin process from a native (i.e. non-Cygwin) Windows process. I have an array of command line arguments which I want passed verbatim to the process, as though it were invoked using execv, with no globbing to take place. I therefore disable globbing by including the noglob option in the CYGWIN environment variable. My reading of winsup/cygwin/dcrt0.cc suggests that I should convert argv to a single string to pass to the Windows CreateProcess API call by protecting any whitespace characters (\t, \r, \n and space itself) with double quotes. Then the escaped individual argv items can be concatenated together with a space between each one. For example: argv[0] = "foo" argv[1] = "bar baz" then the resulting command line string should be: lpCommandLine = "foo bar\" \"baz" and if I've interpreted build_argv and quoted correctly in dcrt0.cc, then as long as allow_glob is 0 (which it is, via the noglob option in the CYGWIN environment variable) then the Cygwin DLL will correctly reconstruct argv based on that string returned by the Windows GetCommandLineW call made in dll_crt0_1. However, it appears that the single quote character may only be used to quote strings if globbing is enabled (dcrt0.cc line 321) so how should one encode the following argv? argv[0] = "foo" argv[1] = "bar \"baz\"" There doesn't seem to be anything along the lines of the trickery in the Windows API's CommandLineToArgvW function if globbing is turned off? Thanks for any pointers to the correct solution! David -- 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