From a928ba1a8d7fa76c5dc379b816a0713ee8b1a619 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 2 Apr 2016 13:05:08 +0200 Subject: [PATCH] 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 --- compat/mingw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 882e0b5a1a7e99..df61138fcd593b 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1294,7 +1294,9 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen si.hStdError = winansi_get_osfhandle(fherr); /* executables and the current directory don't support long paths */ - if (xutftowcs_path(wcmd, cmd) < 0) + if (*argv && !strcmp(cmd, *argv)) + wcmd[0] = L'\0'; + else if (xutftowcs_path(wcmd, cmd) < 0) return -1; if (dir && xutftowcs_path(wdir, dir) < 0) return -1; @@ -1323,8 +1325,8 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen wenvblk = make_environment_block(deltaenv); memset(&pi, 0, sizeof(pi)); - ret = CreateProcessW(wcmd, wargs, NULL, NULL, TRUE, flags, - wenvblk, dir ? wdir : NULL, &si, &pi); + ret = CreateProcessW(*wcmd ? wcmd : NULL, wargs, NULL, NULL, TRUE, + flags, wenvblk, dir ? wdir : NULL, &si, &pi); free(wenvblk); free(wargs);