This is the mail archive of the
cygwin
mailing list for the Cygwin project.
RE: Formatting command line arguments when starting a Cygwin process from a native process
- From: "David Allsopp" <dra27 at cantab dot net>
- To: "'Marco Atzeri'" <marco dot atzeri at gmail dot com>, <cygwin at cygwin dot com>
- Date: Mon, 9 May 2016 17:14:29 +0100
- Subject: RE: Formatting command line arguments when starting a Cygwin process from a native process
- Authentication-results: sourceware.org; auth=none
- References: <005c01d1a6e2$30270ba0$907522e0$ at metastack dot com> <CACoZoo1LObZ0zu9X5O6dV4cO4jN+GO28bdRbuDkTMdaKHXpVbQ at mail dot gmail dot com> <000101d1a76d$c37c6b80$4a754280$ at metastack dot com> <967954968 dot 20160506172040 at yandex dot ru> <006301d1a834$6ccd1380$46673a80$ at cantab dot net> <6e1f2ba2-0c8e-4659-4c5a-d748e90c1ced at lysator dot liu dot se> <8d8fe966-caeb-491c-32e7-fc48ccd56d74 at gmail dot com> <008f01d1aa0a$6b163f30$4142bd90$ at cantab dot net> <21af49f2-f685-828c-6bd4-8d734eedf378 at gmail dot com>
Marco Atzeri wrote:
> On 09/05/2016 17:49, David Allsopp wrote:
> > Marco Atzeri wrote:
> >>
> >> Ultimate overview of MS escape howto :
> >>
> >> https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04
> >> /23/e veryone-quotes-command-line-arguments-the-wrong-way/
> >
> > This is a great article (which I'd not come across before), but this
> > relates to Microsoft's mechanisms for quoting which aren't applicable
> > here - it's definitely the Cygwin DLL which does it!
> >
> >
> > David
> >
>
> Hi David,
Hi!
> I am puzzled, I had the impression you asked:
> "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."
>
> So the exec should be on "Windows process" side, why inside the Cygwin DLL
> ?
In Windows, there is no "exec" - the equivalent functions in Microsoft's C
runtime are themselves emulations boiling down to a CreateProcess call
(unlike on Unix, where the exec family are actual system calls). That
CreateProcess call takes exactly a single string for the entire command line
which the Cygwin DLL then has to convert to argc/argv in order to call the
main function in the Cygwin program started (Microsoft's C runtime has to do
the same thing which is part of what that blog explains). Any sane native
Windows program will use (or be compliant with) CommandLineToArgvW, but no
program has to do it that on Windows (indeed, Cygwin takes "advantage" of
this to do its own thing).
I have total control of my native call to CreateProcess, so it's definitely
about working out exactly what Cygwin does with the command line. AFAICT,
when a Cygwin program execs another Cygwin program, they actually
communicate argc and argv via memory, rather than through the process
invocation (although I'm really not sure that I've interpreted that
correctly) which is why this doesn't come up in pure Cygwin-land.
I think I'm there, it's just not as clean (or documented) as might be nice!
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