[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sending EOF to process as part of comint-simple-send

From: Jim Porter
Subject: Re: Sending EOF to process as part of comint-simple-send
Date: Sat, 14 Jan 2023 21:27:56 -0800

On 1/14/2023 4:18 AM, Eli Zaretskii wrote:
In comint-simple-send, we have:

     (comint-send-string proc send-string))
   (if (and comint-input-sender-no-newline
           (not (string-equal string "")))

Thus, if we send sub-process input without a newline, we then send EOF
to the sub-process, except when the string we send is empty.

I can only understand this logic if it assumes a Posix shell or other
Posix process with which we communicate via a PTY.  Because in that
case, we just send C-d to the process, and AFAIK that will not cause
the sub-process to finish except when C-d is the only character we
So I think comint-simple-send should only send EOF if the
communications with the process are via a PTY, at least if the
sub-process is a real process (as opposed to a network or serial or
pipe process).  Or maybe we should only refrain from sending EOF on

I agree with this: I think we should only call 'process-send-eof' here when communicating via PTY. (To be precise, whenever the process's *stdin* is a PTY; as of Emacs 29, a process's stdin can be a PTY even if its stdout isn't, or vice versa. See commit d7b89ea407.)

I imagine you've looked into the relevant POSIX specs already, but just to explain my reasoning for why I agree... my reading of the POSIX spec[1] for EOF is that the code above is using it as a way to flush the I/O buffer for the PTY, which makes sense to me:

EOF: Special character on input, which is recognized if the
ICANON flag is set. When received, all the bytes waiting to be
read are immediately passed to the process without waiting for a
<newline>, and the EOF is discarded. Thus, if there are no bytes
waiting (that is, the EOF occurred at the beginning of a line), a
byte count of zero shall be returned from the read(),
representing an end-of-file indication. If ICANON is set, the EOF
character shall be discarded when processed.

However, that logic would only apply for PTYs, since a) this documentation is about the POSIX terminal interface, and b) as you said in your message, 'process-send-eof' doesn't actually send an EOF character when communicating via a pipe at all; it closes the file descriptor!

[1] https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap11.html#tag_11_01_09

reply via email to

[Prev in Thread] Current Thread [Next in Thread]