public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Formatting command line arguments when starting a Cygwin process from a native process
@ 2016-05-05 15:24 David Allsopp
  2016-05-05 16:47 ` Erik Soderquist
  0 siblings, 1 reply; 16+ messages in thread
From: David Allsopp @ 2016-05-05 15:24 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-05-10 17:02 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-05 15:24 Formatting command line arguments when starting a Cygwin process from a native process David Allsopp
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

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).