Patch 8.1.2092
Problem:    MS-Windows: redirect in system() does not work.
Solution:   Handle 'shellxescape' and 'shellxquote' better. (Yasuhiro
            Matsumoto, closes #2054)
Files:      src/ex_cmds.c, src/misc2.c, src/testdir/test_system.vim


*** ../vim-8.1.2091/src/ex_cmds.c       2019-09-21 20:46:14.720275786 +0200
--- src/ex_cmds.c       2019-09-28 15:49:49.322697585 +0200
***************
*** 1762,1773 ****
        STRCAT(buf, itmp);
      }
  #else
!     /*
!      * For shells that don't understand braces around commands, at least allow
!      * the use of commands in a pipe.
!      */
!     STRCPY(buf, cmd);
!     if (itmp != NULL)
      {
        char_u  *p;
  
--- 1762,1782 ----
        STRCAT(buf, itmp);
      }
  #else
!     // For shells that don't understand braces around commands, at least allow
!     // the use of commands in a pipe.
!     if (*p_sxe != NUL && *p_sxq == '(')
!     {
!       if (itmp != NULL || otmp != NULL)
!           vim_snprintf((char *)buf, len, "(%s)", (char *)cmd);
!       else
!           STRCPY(buf, cmd);
!       if (itmp != NULL)
!       {
!           STRCAT(buf, " < ");
!           STRCAT(buf, itmp);
!       }
!     }
!     else
      {
        char_u  *p;
  
***************
*** 1819,1836 ****
      char_u    *end;
  
      end = buf + STRLEN(buf);
!     /* find "%s" */
      for (p = opt; (p = vim_strchr(p, '%')) != NULL; ++p)
      {
!       if (p[1] == 's') /* found %s */
            break;
!       if (p[1] == '%') /* skip %% */
            ++p;
      }
      if (p != NULL)
      {
!       *end = ' '; /* not really needed? Not with sh, ksh or bash */
!       vim_snprintf((char *)end + 1, (size_t)(buflen - (end + 1 - buf)),
                                                  (char *)opt, (char *)fname);
      }
      else
--- 1828,1847 ----
      char_u    *end;
  
      end = buf + STRLEN(buf);
!     // find "%s"
      for (p = opt; (p = vim_strchr(p, '%')) != NULL; ++p)
      {
!       if (p[1] == 's') // found %s
            break;
!       if (p[1] == '%') // skip %%
            ++p;
      }
      if (p != NULL)
      {
! #ifdef MSWIN
!       *end++ = ' '; // not really needed? Not with sh, ksh or bash
! #endif
!       vim_snprintf((char *)end, (size_t)(buflen - (end - buf)),
                                                  (char *)opt, (char *)fname);
      }
      else
***************
*** 1838,1844 ****
  #ifdef FEAT_QUICKFIX
                " %s %s",
  #else
!               " %s%s",        /* " > %s" causes problems on Amiga */
  #endif
                (char *)opt, (char *)fname);
  }
--- 1849,1855 ----
  #ifdef FEAT_QUICKFIX
                " %s %s",
  #else
!               " %s%s",        // " > %s" causes problems on Amiga
  #endif
                (char *)opt, (char *)fname);
  }
*** ../vim-8.1.2091/src/misc2.c 2019-09-21 20:46:14.724275765 +0200
--- src/misc2.c 2019-09-28 15:50:16.490609993 +0200
***************
*** 3157,3163 ****
        {
            char_u *ecmd = cmd;
  
!           if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0)
            {
                ecmd = vim_strsave_escaped_ext(cmd, p_sxe, '^', FALSE);
                if (ecmd == NULL)
--- 3157,3163 ----
        {
            char_u *ecmd = cmd;
  
!           if (*p_sxe != NUL && *p_sxq == '(')
            {
                ecmd = vim_strsave_escaped_ext(cmd, p_sxe, '^', FALSE);
                if (ecmd == NULL)
***************
*** 3168,3178 ****
            {
                STRCPY(ncmd, p_sxq);
                STRCAT(ncmd, ecmd);
!               /* When 'shellxquote' is ( append ).
!                * When 'shellxquote' is "( append )". */
!               STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
!                          : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
!                          : p_sxq);
                retval = mch_call_shell(ncmd, opt);
                vim_free(ncmd);
            }
--- 3168,3178 ----
            {
                STRCPY(ncmd, p_sxq);
                STRCAT(ncmd, ecmd);
!               // When 'shellxquote' is ( append ).
!               // When 'shellxquote' is "( append )".
!               STRCAT(ncmd, *p_sxq == '(' ? (char_u *)")"
!                   : *p_sxq == '"' && *(p_sxq+1) == '(' ? (char_u *)")\""
!                   : p_sxq);
                retval = mch_call_shell(ncmd, opt);
                vim_free(ncmd);
            }
*** ../vim-8.1.2091/src/testdir/test_system.vim 2019-08-14 21:12:00.977833219 
+0200
--- src/testdir/test_system.vim 2019-09-28 15:46:10.015375669 +0200
***************
*** 3,11 ****
  source shared.vim
  
  func Test_System()
!   if !executable('echo') || !executable('cat') || !executable('wc')
      return
    endif
    let out = 'echo 123'->system()
    " On Windows we may get a trailing space.
    if out != "123 \n"
--- 3,26 ----
  source shared.vim
  
  func Test_System()
!   if !has('win32')
!     call assert_equal("123\n", system('echo 123'))
!     call assert_equal(['123'], systemlist('echo 123'))
!     call assert_equal('123',   system('cat', '123'))
!     call assert_equal(['123'], systemlist('cat', '123'))
!     call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
!   else
!     call assert_equal("123\n", system('echo 123'))
!     call assert_equal(["123\r"], systemlist('echo 123'))
!     call assert_equal("123",   system('more', '123'))
!     call assert_equal(["123"], systemlist('more', '123'))
!     call assert_equal(["as\<NL>df"], systemlist('more', ["as\<NL>df"]))
!   endif
! 
!   if !executable('cat') || !executable('wc')
      return
    endif
+ 
    let out = 'echo 123'->system()
    " On Windows we may get a trailing space.
    if out != "123 \n"
***************
*** 13,26 ****
    endif
  
    let out = 'echo 123'->systemlist()
!   " On Windows we may get a trailing space and CR.
!   if out != ["123 \r"]
!     call assert_equal(['123'], out)
    endif
  
!   call assert_equal('123',   system('cat', '123'))
!   call assert_equal(['123'], systemlist('cat', '123'))
!   call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"]))
  
    new Xdummy
    call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
--- 28,44 ----
    endif
  
    let out = 'echo 123'->systemlist()
!   if !has('win32')
!     call assert_equal(["123"], out)
!   else
!     call assert_equal(["123\r"], out)
    endif
  
!   if executable('cat')
!     call assert_equal('123',   system('cat', '123'))  
!     call assert_equal(['123'], systemlist('cat', '123'))      
!     call assert_equal(["as\<NL>df"], systemlist('cat', ["as\<NL>df"])) 
!   endif
  
    new Xdummy
    call setline(1, ['asdf', "pw\<NL>er", 'xxxx'])
***************
*** 39,47 ****
      call assert_equal(['3'],  out)
    endif
  
!   let out = systemlist('cat', bufnr('%'))
!   " On Windows we may get a trailing CR.
!   if out != ["asdf\r", "pw\<NL>er\r", "xxxx\r"]
      call assert_equal(['asdf', "pw\<NL>er", 'xxxx'],  out)
    endif
    bwipe!
--- 57,67 ----
      call assert_equal(['3'],  out)
    endif
  
!   if !has('win32')
!     let out = systemlist('cat', bufnr('%'))
!     call assert_equal(['asdf', "pw\<NL>er", 'xxxx'],  out)
!   else
!     let out = systemlist('more', bufnr('%'))
      call assert_equal(['asdf', "pw\<NL>er", 'xxxx'],  out)
    endif
    bwipe!
*** ../vim-8.1.2091/src/version.c       2019-09-28 15:23:57.033274535 +0200
--- src/version.c       2019-09-28 15:48:17.542988130 +0200
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     2092,
  /**/

-- 
The question is:  What do you do with your life?
The wrong answer is: Become the richest guy in the graveyard.
                                (billionaire and Oracle founder Larry Ellison)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/201909281352.x8SDq5ui015910%40masaka.moolenaar.net.

Raspunde prin e-mail lui