comparison 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
comparison
equal deleted inserted replaced
18240:7aed836f50f7 18241:85160a3649b9
25 25
26 int 26 int
27 main(void) 27 main(void)
28 { 28 {
29 const wchar_t *p; 29 const wchar_t *p;
30 wchar_t *cmd;
31 size_t cmdlen;
30 int retval; 32 int retval;
31 int inquote = 0; 33 int inquote = 0;
32 int silent = 0; 34 int silent = 0;
33 HANDLE hstdout; 35 HANDLE hstdout;
34 DWORD written; 36 DWORD written;
61 p += 3; 63 p += 3;
62 while (*p == L' ') 64 while (*p == L' ')
63 ++p; 65 ++p;
64 } 66 }
65 67
66 /* Print the command, including quotes and redirection. */ 68 // Print the command, including quotes and redirection.
67 hstdout = GetStdHandle(STD_OUTPUT_HANDLE); 69 hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
68 WriteConsoleW(hstdout, p, wcslen(p), &written, NULL); 70 WriteConsoleW(hstdout, p, wcslen(p), &written, NULL);
69 WriteConsoleW(hstdout, L"\r\n", 2, &written, NULL); 71 WriteConsoleW(hstdout, L"\r\n", 2, &written, NULL);
72
73 // If the command starts and ends with double quotes,
74 // Enclose the command in parentheses.
75 cmd = NULL;
76 cmdlen = wcslen(p);
77 if (cmdlen >= 2 && p[0] == L'"' && p[cmdlen - 1] == L'"')
78 {
79 cmdlen += 3;
80 cmd = (wchar_t *)malloc(cmdlen * sizeof(wchar_t));
81 if (cmd == NULL)
82 {
83 perror("vimrun malloc(): ");
84 return -1;
85 }
86 _snwprintf(cmd, cmdlen, L"(%s)", p);
87 p = cmd;
88 }
70 89
71 /* 90 /*
72 * Do it! 91 * Do it!
73 */ 92 */
74 retval = _wsystem(p); 93 retval = _wsystem(p);
94
95 if (cmd)
96 free(cmd);
75 97
76 if (retval == -1) 98 if (retval == -1)
77 perror("vimrun system(): "); 99 perror("vimrun system(): ");
78 else if (retval != 0) 100 else if (retval != 0)
79 printf("shell returned %d\n", retval); 101 printf("shell returned %d\n", retval);