result)))
(defun eshell-resume-command (proc status)
- "Resume the current command when a process ends."
- (when proc
- (unless (or (not (stringp status))
- (string= "stopped" status)
- (string-match eshell-reset-signals status))
- (if (eq proc (eshell-tail-process))
- (eshell-resume-eval)))))
+ "Resume the current command when a pipeline ends."
+ (when (and proc
+ ;; Make sure STATUS is something we want to handle.
+ (stringp status)
+ (not (string= "stopped" status))
+ (not (string-match eshell-reset-signals status))
+ ;; Make sure PROC is one of our foreground processes and
+ ;; that all of those processes are now dead.
+ (member proc eshell-last-async-procs)
+ (not (seq-some #'process-live-p eshell-last-async-procs)))
+ (eshell-resume-eval)))
(defun eshell-resume-eval ()
"Destructively evaluate a form which may need to be deferred."
(eshell-match-command-output "*echo hi | echo bye"
"bye\nhi\n")))
+(ert-deftest esh-cmd-test/pipeline-wait/multi-proc ()
+ "Check that a pipeline waits for all its processes before returning."
+ (skip-unless (and (executable-find "echo")
+ (executable-find "sh")
+ (executable-find "rev")))
+ (with-temp-eshell
+ (eshell-match-command-output
+ "*echo hello | sh -c 'sleep 1; rev' 1>&2 | *echo goodbye"
+ "goodbye\nolleh\n")))
+
(ert-deftest esh-cmd-test/pipeline-wait/subcommand ()
"Check that piping with an asynchronous subcommand waits for the subcommand."
(skip-unless (and (executable-find "echo")