comparison src/os_win32.c @ 3357:397e7e49bb0b v7.3.445

updated for version 7.3.445 Problem: Can't properly escape commands for cmd.exe. Solution: Default 'shellxquote' to '('. Append ')' to make '(command)'. No need to use "/s" for 'shellcmdflag'.
author Bram Moolenaar <bram@vim.org>
date Sun, 19 Feb 2012 18:19:30 +0100
parents 07bc2ccfe555
children 6a03b0ea2e12
comparison
equal deleted inserted replaced
3356:b37888de599c 3357:397e7e49bb0b
3906 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10); 3906 STRLEN(p_sh) + STRLEN(p_shcf) + STRLEN(cmd) + 10);
3907 3907
3908 newcmd = lalloc(cmdlen, TRUE); 3908 newcmd = lalloc(cmdlen, TRUE);
3909 if (newcmd != NULL) 3909 if (newcmd != NULL)
3910 { 3910 {
3911 char_u *cmdbase = (*cmd == '"' ? cmd + 1 : cmd); 3911 char_u *cmdbase = cmd;
3912 3912
3913 /* Skip a leading ", ( and "(. */
3914 if (*cmdbase == '"' )
3915 ++cmdbase;
3916 if (*cmdbase == '(')
3917 ++cmdbase;
3913 if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5])) 3918 if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
3914 { 3919 {
3915 STARTUPINFO si; 3920 STARTUPINFO si;
3916 PROCESS_INFORMATION pi; 3921 PROCESS_INFORMATION pi;
3917 DWORD flags = CREATE_NEW_CONSOLE; 3922 DWORD flags = CREATE_NEW_CONSOLE;
3951 3956
3952 /* When the command is in double quotes, but 'shellxquote' is 3957 /* When the command is in double quotes, but 'shellxquote' is
3953 * empty, keep the double quotes around the command. 3958 * empty, keep the double quotes around the command.
3954 * Otherwise remove the double quotes, they aren't needed 3959 * Otherwise remove the double quotes, they aren't needed
3955 * here, because we don't use a shell to run the command. */ 3960 * here, because we don't use a shell to run the command. */
3956 if (*cmd == '"' && *p_sxq == NUL) 3961 if (cmdbase > cmd)
3957 { 3962 {
3958 newcmd[0] = '"'; 3963 if (STRNCMP(cmd, p_sxq, cmd - cmdbase) != 0)
3959 STRCPY(newcmd + 1, cmdbase); 3964 {
3960 } 3965 STRCPY(newcmd, cmd);
3961 else 3966 }
3962 { 3967 else
3963 STRCPY(newcmd, cmdbase); 3968 {
3964 if (*cmd == '"' && *newcmd != NUL) 3969 char_u *p;
3965 newcmd[STRLEN(newcmd) - 1] = NUL; 3970
3971 STRCPY(newcmd, cmdbase);
3972 /* Remove a trailing ", ) and )" if they have a match
3973 * at the start of the command. */
3974 p = newcmd + STRLEN(newcmd);
3975 if (p > newcmd && p[-1] == '"' && *cmd == '"')
3976 *--p = NUL;
3977 if (p > newcmd && p[-1] == ')'
3978 && (*cmd =='(' || cmd[1] == '('))
3979 *--p = NUL;
3980 }
3966 } 3981 }
3967 3982
3968 /* 3983 /*
3969 * Now, start the command as a process, so that it doesn't 3984 * Now, start the command as a process, so that it doesn't
3970 * inherit our handles which causes unpleasant dangling swap 3985 * inherit our handles which causes unpleasant dangling swap
3971 * files if we exit before the spawned process 3986 * files if we exit before the spawned process
3972 */ 3987 */
3973 if (CreateProcess (NULL, // Executable name 3988 if (CreateProcess(NULL, // Executable name
3974 newcmd, // Command to execute 3989 newcmd, // Command to execute
3975 NULL, // Process security attributes 3990 NULL, // Process security attributes
3976 NULL, // Thread security attributes 3991 NULL, // Thread security attributes
3977 FALSE, // Inherit handles 3992 FALSE, // Inherit handles
3978 flags, // Creation flags 3993 flags, // Creation flags