public
Created

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
diff -r dd78da101764 src/os_win32.c
--- a/src/os_win32.c Tue Feb 21 21:22:45 2012 +0100
+++ b/src/os_win32.c Wed Feb 22 22:00:04 2012 +0900
@@ -3933,7 +3933,9 @@
else
{
/* we use "command" or "cmd" to start the shell; slow but easy */
- char_u *cmdbase = cmd;
+ char_u *newcmd = NULL;
+ char_u *cmdbase = cmd;
+ long_u cmdlen;
/* Skip a leading ", ( and "(. */
if (*cmdbase == '"' )
@@ -3993,12 +3995,37 @@
*--p = NUL;
}
+ newcmd = cmdbase;
+ unescape_shellxquote(cmdbase, p_sxe);
/*
- * Unescape characters in shellxescape. This is workaround for
- * /b option. Only redirect character should be unescaped.
+ * If creating new console, arguments are passed to the
+ * 'cmd.exe' as it is. If it's not, arguments are not treated
+ * correctly for current 'cmd.exe'. So unescape characters in
+ * shellxescape except '|' for avoiding to be treated as
+ * argument to them. Pass the arguments to sub-shell.
*/
- unescape_shellxquote(cmdbase,
- (flags & CREATE_NEW_CONSOLE) ? p_sxe : "<>");
+ if ((flags & CREATE_NEW_CONSOLE) == 0)
+ {
+ char_u *subcmd;
+ char_u *cmd_shell = mch_getenv("COMSPEC");
+ if (cmd_shell == NULL)
+ cmd_shell = default_shell();
+
+ subcmd = vim_strsave_escaped_ext(cmdbase, "|", '^', FALSE);
+ if (subcmd != NULL)
+ {
+ /* make "cmd.exe /c arguments" */
+ cmdlen = STRLEN(cmd_shell) + STRLEN(subcmd) + 5;
+
+ newcmd = lalloc(cmdlen, TRUE);
+ if (newcmd)
+ vim_snprintf((char *)newcmd, cmdlen, "%s /c %s",
+ cmd_shell, subcmd);
+ else
+ newcmd = cmdbase;
+ vim_free(subcmd);
+ }
+ }
/*
* Now, start the command as a process, so that it doesn't
@@ -4006,7 +4033,7 @@
* files if we exit before the spawned process
*/
if (CreateProcess(NULL, // Executable name
- cmdbase, // Command to execute
+ newcmd, // Command to execute
NULL, // Process security attributes
NULL, // Thread security attributes
FALSE, // Inherit handles
@@ -4023,6 +4050,10 @@
EMSG(_("E371: Command not found"));
#endif
}
+
+ if (newcmd != cmdbase)
+ vim_free(newcmd);
+
if (si.hStdInput != NULL)
{
/* Close the handle to \\.\NUL */
@@ -4034,8 +4065,7 @@
}
else
{
- char_u *newcmd;
- long_u cmdlen = (
+ cmdlen = (
#ifdef FEAT_GUI_W32
(allowPiping && !p_stmp ? 0 : STRLEN(vimrun_path)) +
#endif

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.