diff src/vimrun.c @ 18241:85160a3649b9 v8.1.2115

patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space Commit: https://github.com/vim/vim/commit/2efc44b3f0b6bd8307cb281af095e08e15ab1c24 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 5 12:09:32 2019 +0200 patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a space Problem: MS-Windows: shell commands fail if &shell contains a space. Solution: Use quotes instead of escaping. (closes https://github.com/vim/vim/issues/4920)
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Oct 2019 12:15:04 +0200
parents 7e733046db1d
children 2559dc02bd64
line wrap: on
line diff
--- a/src/vimrun.c
+++ b/src/vimrun.c
@@ -27,6 +27,8 @@
 main(void)
 {
     const wchar_t   *p;
+    wchar_t	    *cmd;
+    size_t	    cmdlen;
     int		    retval;
     int		    inquote = 0;
     int		    silent = 0;
@@ -63,16 +65,36 @@ main(void)
 	    ++p;
     }
 
-    /* Print the command, including quotes and redirection. */
+    // Print the command, including quotes and redirection.
     hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
     WriteConsoleW(hstdout, p, wcslen(p), &written, NULL);
     WriteConsoleW(hstdout, L"\r\n", 2, &written, NULL);
 
+    // If the command starts and ends with double quotes,
+    // Enclose the command in parentheses.
+    cmd = NULL;
+    cmdlen = wcslen(p);
+    if (cmdlen >= 2 && p[0] == L'"' && p[cmdlen - 1] == L'"')
+    {
+	cmdlen += 3;
+	cmd = (wchar_t *)malloc(cmdlen * sizeof(wchar_t));
+	if (cmd == NULL)
+	{
+	    perror("vimrun malloc(): ");
+	    return -1;
+	}
+	_snwprintf(cmd, cmdlen, L"(%s)", p);
+	p = cmd;
+    }
+
     /*
      * Do it!
      */
     retval = _wsystem(p);
 
+    if (cmd)
+	free(cmd);
+
     if (retval == -1)
 	perror("vimrun system(): ");
     else if (retval != 0)