]> git.eshelyaron.com Git - emacs.git/commitdiff
Be more careful about when to print abnormal exit status in Eshell
authorJim Porter <jporterbugs@gmail.com>
Tue, 12 Sep 2023 04:32:05 +0000 (21:32 -0700)
committerJim Porter <jporterbugs@gmail.com>
Tue, 12 Sep 2023 18:44:27 +0000 (11:44 -0700)
* 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
test/lisp/eshell/esh-proc-tests.el

index 50f8c026fabff840ec91e0af1363097b57738276..f5fd982b1a482971a0fd8f95c81fa7708a384ab1 100644 (file)
@@ -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.
index 5164dea8ce162768e1cf444cd0cd67b231f69816..52f8aeaedbe041a6a4e34b9750c036d349abbe7f 100644 (file)
@@ -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> #<buffer %s>" tempbuf))
+       (kill-process (eshell-head-process))))
+    (should (equal (buffer-string) ""))))
+
 \f
 ;; Remote processes