diff src/os_win32.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 88716bc1c20b
children 5218e26c658f
line wrap: on
line diff
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -4490,8 +4490,25 @@ mch_system_c(char *cmd, int options UNUS
 {
     int		ret;
     WCHAR	*wcmd;
-
-    wcmd = enc_to_utf16((char_u *)cmd, NULL);
+    char_u	*buf;
+    size_t	len;
+
+    // If the command starts and ends with double quotes, enclose the command
+    // in parentheses.
+    len = STRLEN(cmd);
+    if (len >= 2 && cmd[0] == '"' && cmd[len - 1] == '"')
+    {
+	len += 3;
+	buf = alloc(len);
+	if (buf == NULL)
+	    return -1;
+	vim_snprintf((char *)buf, len, "(%s)", cmd);
+	wcmd = enc_to_utf16(buf, NULL);
+	free(buf);
+    }
+    else
+	wcmd = enc_to_utf16((char_u *)cmd, NULL);
+
     if (wcmd == NULL)
 	return -1;