public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: <cygwin@cygwin.com>
Subject: Formatting command line arguments when starting a Cygwin process from a native process
Date: Thu, 05 May 2016 15:24:00 -0000	[thread overview]
Message-ID: <005c01d1a6e2$30270ba0$907522e0$@metastack.com> (raw)

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

             reply	other threads:[~2016-05-05 15:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-05 15:24 David Allsopp [this message]
2016-05-05 16:47 ` Erik Soderquist
2016-05-06  8:03   ` David Allsopp
2016-05-06 13:17     ` Erik Soderquist
2016-05-06 14:35     ` Andrey Repin
2016-05-07  7:45       ` David Allsopp
2016-05-09  9:43         ` Peter Rosin
2016-05-09 10:06           ` Marco Atzeri
2016-05-09 15:49             ` David Allsopp
2016-05-09 16:02               ` Marco Atzeri
2016-05-09 16:14                 ` David Allsopp
2016-05-09 15:49           ` David Allsopp
2016-05-09 14:57         ` Aaron Digulla
2016-05-09 15:19           ` David Allsopp
2016-05-10 13:30             ` Aaron Digulla
2016-05-10 17:02               ` David Allsopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='005c01d1a6e2$30270ba0$907522e0$@metastack.com' \
    --to=dra-news@metastack.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).