This is the mail archive of the
mailing list for the Cygwin project.
Formatting command line arguments when starting a Cygwin process from a native process
- From: "David Allsopp" <dra-news at metastack dot com>
- To: <cygwin at cygwin dot com>
- Date: Thu, 5 May 2016 17:24:14 +0200
- Subject: Formatting command line arguments when starting a Cygwin process from a native process
- Authentication-results: sourceware.org; auth=none
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.
argv = "foo"
argv = "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
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 = "foo"
argv = "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!
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple