From bda5d1dbe322b8fdcac601753f74d1a62d9b256c Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Thu, 27 Jan 2022 23:13:36 -0800 Subject: [PATCH 1/3] Ensure that tailproc is set for the last process in an Eshell pipeline In particular, this used to fail for pipelines where the last process in the pipeline came from the first element of the pipeline. This could happen when a process was piped to an ordinary Lisp function, like in '*echo hi | echo bye'. * lisp/eshell/esh-cmd.el (eshell-do-pipelines): Set the tailproc even for the first process in the pipeline. * test/lisp/eshell/eshell-tests.el (eshell-test/pipe-tailproc): New test. --- lisp/eshell/esh-cmd.el | 7 ++++--- test/lisp/eshell/eshell-tests.el | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 04d65df4f3..14139896dd 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -764,8 +764,7 @@ eshell-do-pipelines (eshell-set-output-handle ,eshell-output-handle 'append nextproc) (eshell-set-output-handle ,eshell-error-handle - 'append nextproc) - (setq tailproc (or tailproc nextproc)))) + 'append nextproc))) ,(let ((head (car pipeline))) (if (memq (car head) '(let progn)) (setq head (car (last head)))) @@ -781,7 +780,9 @@ eshell-do-pipelines ,(cond ((not notfirst) (quote 'first)) ((cdr pipeline) t) (t (quote 'last))))) - ,(car pipeline)))))) + (let ((proc ,(car pipeline))) + (setq tailproc (or tailproc proc)) + proc)))))) (defmacro eshell-do-pipelines-synchronously (pipeline) "Execute the commands in PIPELINE in sequence synchronously. diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index 542815df80..7658d5f551 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -129,6 +129,13 @@ eshell-test/interp-cmd-external-concat (eshell-command-result-p "echo ${echo hi}-${*echo there}" "hi-there\n"))) +(ert-deftest eshell-test/pipe-tailproc () + "Check that piping a process to a non-process command waits for the process" + (skip-unless (executable-find "echo")) + (with-temp-eshell + (eshell-command-result-p "*echo hi | echo bye" + "bye\nhi\n"))) + (ert-deftest eshell-test/window-height () "$LINES should equal (window-height)" (should (eshell-test-command-result "= $LINES (window-height)"))) -- 2.25.1