From a0c8b458209b127834af7a70be6024bf65ae06b7 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Mon, 11 Sep 2023 21:32:05 -0700 Subject: [PATCH] Be more careful about when to print abnormal exit status in Eshell * lisp/eshell/esh-proc.el (eshell-sentinel): Only output abnormal status when stderr is interactive. * test/lisp/eshell/esh-proc-tests.el (esh-proc-test/kill-process/redirect-message): New test. --- lisp/eshell/esh-proc.el | 8 +++++--- test/lisp/eshell/esh-proc-tests.el | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el index 50f8c026fab..f5fd982b1a4 100644 --- a/lisp/eshell/esh-proc.el +++ b/lisp/eshell/esh-proc.el @@ -496,12 +496,14 @@ PROC is the process that's exiting. STRING is the exit message." ;; not the pipe process (if any). (status (when (= index eshell-output-handle) (process-exit-status proc)))) - ;; Write the exit message if the status is abnormal and - ;; the process is already writing to the terminal. + ;; Write the exit message for the last process in the + ;; foreground pipeline if its status is abnormal and + ;; stderr is already writing to the terminal. (when (and (eq proc (eshell-tail-process)) + (eshell-interactive-output-p eshell-error-handle handles) (not (string-match "^\\(finished\\|exited\\)" string))) - (funcall (process-filter proc) proc string)) + (eshell-output-object string eshell-error-handle handles)) (process-put proc :eshell-pending nil) ;; If we're in the middle of handling output from this ;; process then schedule the EOF for later. diff --git a/test/lisp/eshell/esh-proc-tests.el b/test/lisp/eshell/esh-proc-tests.el index 5164dea8ce1..52f8aeaedbe 100644 --- a/test/lisp/eshell/esh-proc-tests.el +++ b/test/lisp/eshell/esh-proc-tests.el @@ -313,6 +313,16 @@ write the exit status to the pipe. See bug#54136." output-start (eshell-end-of-output)) ""))))) +(ert-deftest esh-proc-test/kill-process/redirect-message () + "Test that killing a process with a redirected stderr omits the exit status." + (skip-unless (executable-find "sleep")) + (with-temp-buffer + (let ((tempbuf (current-buffer))) + (with-temp-eshell + (eshell-insert-command (format "sleep 100 2> #" tempbuf)) + (kill-process (eshell-head-process)))) + (should (equal (buffer-string) "")))) + ;; Remote processes -- 2.39.5