gspawn-win32-helper

Tor Lillqvist <[email protected]> Mon, 20 Jan 2003 23:43:06 +0000
Newsgroups gmane.comp.video.gimp.windows.devel
Message-ID <[email protected]>
"alex_shaduri <[email protected]>" <[email protected]> writes:
 > "'c:\\program files\\internet explorer\\iexplore.exe'", it
 > says "Failed to execute child process: no such file or directory".

and later:
 > Success!  The path "'\"c:\\program files\\internet
 > explorer\\iexplore.exe\"'" (putting the real path into escaped
 > double quotes and then into single quotes and double-quoting
 > everything for the string to work as a C string) seems to work.

Ouch! I think what happens is that the outer set of single quotes tell
the g_shell_parse_argv() to leave what's inside the single quotes
alone, and the double quotes are noticed by the MSVCRT startup code in
gspawn-win32-helper so that the program name gets picked up as a
single argument, and subsequently passed to spawnv() as the program
name.

(Remember that in the underlying Win32 API a command line is what is
actually used in the CreateProcess() call. It's the C runtime that
translates back and forth between argv and command line in the spawn*
functions and in the startup code. Those with C runtime source (part
of the Platform SDK), check the files cenvarg.c and stdargv.c. Also
dospawn.c, crt0.c and wincmdln.c might be of interest.

Would it perhaps be easier to avoid the shell-style command line
parsing inside GLib completely, and build the argv manually and use
g_spawn_async() call instead? Hmm, I guess, as gspawn-win32.c
currently is coded, you would still need the double quotes, though.

> The single quotes I enclosed the paths in come from glib
> documentation,

Hmm, either I should fix the documentation and make it say that you
need both single and double quotes as above, or fix the implementation
so that it matches the documentation. (I.e. consider the current
behaviour as a bug.)

I think the latter is better, as the need for the double quotes comes
from the implementation detail that the argv is passed to the helper
process. It really should be gspawn-win32.c's business to add double
quotes around argv elements that need them when passing the argv to
the helper process. And, as I in fact intend to get rid of the helper
process in suitable cases, in those cases the double quotes aren't
needed.

Of course, considering the current gspawn-win32.c behaviour buggy and
fixing it means that you will need to change your code when you
install a fixed GLib. Is this a problem? Should this change be
synchronised with a micro version number chnage (i.e. do it in 2.2.1)?

I have opened a bug on bugzilla for this, #104014.

--tml