]> granicus.if.org Git - vim/commitdiff
patch 8.0.1820: terminal window redirecting stdout does not show stderr v8.0.1820
authorBram Moolenaar <Bram@vim.org>
Sat, 12 May 2018 15:42:42 +0000 (17:42 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 12 May 2018 15:42:42 +0000 (17:42 +0200)
Problem:    Terminal window redirecting stdout does not show stderr. (Matéo
            Zanibelli)
Solution:   When stdout is not connected to pty_master_fd then use it for
            stderr. (closes #2903)

src/os_unix.c
src/testdir/test_terminal.vim
src/version.c

index 495d13475b360fd314bd02e1de6f68ce66242db8..1609bb8e2d7b58a124ce67b34f5d3d0cbf64908e 100644 (file)
@@ -5645,7 +5645,12 @@ mch_job_start(char **argv, job_T *job, jobopt_T *options)
        /* When using pty_master_fd only set it for stdout, do not duplicate it
         * for stderr, it only needs to be read once. */
        int err_fd = use_out_for_err || use_file_for_err || use_null_for_err
-                     ? INVALID_FD : fd_err[0] < 0 ? INVALID_FD : fd_err[0];
+                     ? INVALID_FD
+                     : fd_err[0] >= 0
+                        ? fd_err[0]
+                        : (out_fd == pty_master_fd
+                                ? INVALID_FD
+                                : pty_master_fd);
 
        channel_set_pipes(channel, in_fd, out_fd, err_fd);
        channel_set_job(channel, job, options);
index 5dfe0275d4b25f13cee02ea9a2919f3399c7fe9e..14466900a1c3c9a4e7da2f0f18feae52c185fc81 100644 (file)
@@ -1484,3 +1484,25 @@ func Test_terminal_termwinkey()
   call feedkeys("\<C-L>\<C-C>", 'tx')
   call WaitForAssert({-> assert_equal("dead", job_status(job))})
 endfunc
+
+func Test_terminal_out_err()
+  if !has('unix')
+    return
+  endif
+  call writefile([
+       \ '#!/bin/sh',
+       \ 'echo "this is standard error" >&2',
+       \ 'echo "this is standard out" >&1',
+       \ ], 'Xechoerrout.sh')
+  call setfperm('Xechoerrout.sh', 'rwxrwx---')
+
+  let outfile = 'Xtermstdout'
+  let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile})
+  call WaitForAssert({-> assert_inrange(1, 2, len(readfile(outfile)))})
+  call assert_equal("this is standard out", readfile(outfile)[0])
+  call assert_equal('this is standard error', term_getline(buf, 1))
+
+  exe buf . 'bwipe'
+  call delete('Xechoerrout.sh')
+  call delete(outfile)
+endfunc
index a6fd36a1258b0f512b1db9c6091fb4eb7fab554d..7d86c010eb75c153dc18976a977a0701f61c7fbd 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1820,
 /**/
     1819,
 /**/