Re: spawn problem - success

Bill Nalen/Towers Perrin writes:
 > I also realized that you need to use foward slashes instead of windows
 > backward slashes and I need to use the eight character limit on paths.  So
 > instead of c:\program files\winamp\winamp.exe

 > I need to use c:/progra~1/winamp/winamp.exe

Umm, yes, that is a workaround, but a bit misleading. It's not that
the g_spawn_command_line_async() function would have been on purpose
written to require (forward) slashes and 8.3 names, that just happens
to be one way to get around an unfortunate problem you discovered.

What actually is happening is that g_spawn_command_line_async()
processes the passed "command line" as Unix shells do. (As it is
supposed to do, and as documented.) It uses g_shell_parse_argv() for
that. This means that the backslash is used as a "quote" character. In
this case, as the chars following backslahses are 'p', 'w' and 'w',
the backslashes just get eaten. Also, the space in "program files"
acts as a delimiter. So, what happens is that it tries to run
"c:program" with the argument "fileswinampwinamp.exe".

If you do want to specify the path of the program to run in the
canonical Windows way (backslashes, long file names including
potential spaces), you need to enclose it in single quotes, like:

g_spawn_command_line_async("'c:\\program files\\winamp\\winamp.exe'", &err);

or, you could quote the backslashes (with backslash):

g_spawn_command_line_async("c:\\\\program files\\\\winamp\\\\winamp.exe", &err);

Yes, both ways are a bit odd, and probably counter-intuitive.

Alternatively you could call g_spawn_async() directly, passing in a
argv with just two elements: the program name as such (without any
extra quotes or doubled backslashes) and the NULL terminator:

argv[0] = "c:\\program files\\winamp\\winamp.exe"
argv[1] = NULL;
g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
               NULL, NULL, NULL, &err);

I think I would recommend this way. Perhaps documentation should be
added to the g_spawn_command_line_* functions that Windows programmers
should be aware of g_shell_parse_argv() processing the command line.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]