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