summaryrefslogtreecommitdiff
path: root/src/vimrun.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-10-05 12:09:32 +0200
committerBram Moolenaar <Bram@vim.org>2019-10-05 12:09:32 +0200
commit2efc44b3f0b6bd8307cb281af095e08e15ab1c24 (patch)
tree4245a8fef089e696e8eb6df87e02cafbc4d7806e /src/vimrun.c
parentfd00c042afc40539447e798aadbd0a2219fdbdc1 (diff)
downloadvim-git-2efc44b3f0b6bd8307cb281af095e08e15ab1c24.tar.gz
patch 8.1.2115: MS-Windows: shell commands fail if &shell contains a spacev8.1.2115
Problem: MS-Windows: shell commands fail if &shell contains a space. Solution: Use quotes instead of escaping. (closes #4920)
Diffstat (limited to 'src/vimrun.c')
-rw-r--r--src/vimrun.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/vimrun.c b/src/vimrun.c
index ece20f839..26c4aa4c6 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 @@ 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)