Subject: Re: bug#79079: 31.0.50; Piped command output is sometimes lost in Eshell

From: Eli Zaretskii <[email-masked]>
Date: Sat, 16 Aug 2025 09:04:27 +0300

> Date: Fri, 15 Aug 2025 13:55:27 -0700
> From: Jim Porter <[email-masked]>
> Cc: [email-masked], [email-masked], [email-masked]
> 
>  	      else if (errno == EPIPE)
>  		{
> -		  p->raw_status_new = 0;
> -		  pset_status (p, list2 (Qexit, make_fixnum (256)));
> -		  p->tick = ++process_tick;
> -		  deactivate_process (proc);
> +		  close_process_fd(&p->open_fd[WRITE_TO_SUBPROCESS]);
                                  ^
SPC before the open parenthesis missing there.

> +(defun process-tests/broken-pipe (connection-type)
> +  "Test handling of broken pipes; see bug#79079.
> +This test runs a shell script that reads a line of text and closes
> +stdin.  We send two lines of text to the script; the second should
> +signal an error indicating that the pipe has been closed.  The script
> +should also run to completion, printing out the line of text it read."
> +  (with-temp-buffer
> +    (let ((saw-error nil)
> +          (proc (make-process
> +                 :name "test" :buffer (current-buffer)
> +                 :command '("sh" "-c"
> +                            "read line; exec 0<&-; sleep 1; echo $line")

This will not work on Windows.  Can you come up with a test which
doesn't use features specific Posix shells?  E.g., can you perhaps use
Emacs itself as the other end of the pipe, running some special Lisp
program?

> +  (ert-deftest process-tests/broken-pipe/pty ()
> +    (process-tests/broken-pipe 'pty))
> +
> +  (ert-deftest process-tests/broken-pipe/pipe-stdin ()
> +    (process-tests/broken-pipe '(pipe . pty)))
> +
> +  (ert-deftest process-tests/broken-pipe/pty-stdin ()
> +    (process-tests/broken-pipe '(pty . pipe))))
> +

The PTY tests should be skipped on Windows, since PTYs aren't
supported there.

Thanks.