Skip to content

Commit a928ba1

Browse files
committed
mingw: support spawning programs containing spaces in their names
The CreateProcessW() function does not really support spaces in its first argument, lpApplicationName. But it supports passing NULL as lpApplicationName, which makes it figure out the application from the (possibly quoted) first argument of lpCommandLine. Let's use that trick (if we are certain that the first argument matches the executable's path) to support launching programs whose path contains spaces. This fixes https://github.com/git-for-windows/git/issue/692 Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 854256e commit a928ba1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

compat/mingw.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
12941294
si.hStdError = winansi_get_osfhandle(fherr);
12951295

12961296
/* executables and the current directory don't support long paths */
1297-
if (xutftowcs_path(wcmd, cmd) < 0)
1297+
if (*argv && !strcmp(cmd, *argv))
1298+
wcmd[0] = L'\0';
1299+
else if (xutftowcs_path(wcmd, cmd) < 0)
12981300
return -1;
12991301
if (dir && xutftowcs_path(wdir, dir) < 0)
13001302
return -1;
@@ -1323,8 +1325,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
13231325
wenvblk = make_environment_block(deltaenv);
13241326

13251327
memset(&pi, 0, sizeof(pi));
1326-
ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
1327-
wenvblk, dir ? wdir : NULL, &si, &pi);
1328+
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL, TRUE,
1329+
flags, wenvblk, dir ? wdir : NULL, &si, &pi);
13281330

13291331
free(wenvblk);
13301332
free(wargs);

0 commit comments

Comments
 (0)