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 #4920)
diff --git a/src/vimrun.c b/src/vimrun.c
index ece20f8..26c4aa4 100644
--- 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 @@
++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)