Skip to content

Commit 45f1117

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 03e1632 commit 45f1117

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
@@ -1445,7 +1445,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14451445
si.hStdError = winansi_get_osfhandle(fherr);
14461446

14471447
/* executables and the current directory don't support long paths */
1448-
if (xutftowcs_path(wcmd, cmd) < 0)
1448+
if (*argv && !strcmp(cmd, *argv))
1449+
wcmd[0] = L'\0';
1450+
else if (xutftowcs_path(wcmd, cmd) < 0)
14491451
return -1;
14501452
if (dir && xutftowcs_path(wdir, dir) < 0)
14511453
return -1;
@@ -1474,8 +1476,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
14741476
wenvblk = make_environment_block(deltaenv);
14751477

14761478
memset(&pi, 0, sizeof(pi));
1477-
ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags,
1478-
wenvblk, dir ? wdir : NULL, &si, &pi);
1479+
ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL, TRUE,
1480+
flags, wenvblk, dir ? wdir : NULL, &si, &pi);
14791481

14801482
free(wenvblk);
14811483
free(wargs);

0 commit comments

Comments
 (0)