unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Sending EOF to process as part of comint-simple-send
@ 2023-01-14 12:18 Eli Zaretskii
  2023-01-15  5:27 ` Jim Porter
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2023-01-14 12:18 UTC (permalink / raw)
  To: emacs-devel

For the background, see

  https://lists.gnu.org/archive/html/help-gnu-emacs/2023-01/msg00097.html
  https://lists.gnu.org/archive/html/help-gnu-emacs/2023-01/msg00156.html

Note that this was on MS-Windows, where we communicate with
sub-processes via pipes, as PTYs are not available.

In comint-simple-send, we have:

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

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
send.  But if the communications with the sub-process are via a pipe,
then process-send-eof says:

  If PROCESS is a network connection, or is a process communicating
  through a pipe (as opposed to a pty), then you cannot send any more
  text to PROCESS after you call this function.

The implementation closes the file descriptor through which we write
to the sub-process, which is supposed to produce EOF on input for the
sub-process, and interactive sub-processes will exit.  And even if the
sub-process doesn't exit, we will not be able to write to it anymore.

The change to send EOF was installed 21 years ago, as part of commit
004a541.  The only reference to some related issue that I can find is
this bug report:

  https://lists.gnu.org/archive/html/bug-gnu-emacs/2002-01/msg00195.html

which indeed describes a situation where we want to send to a process
input without ending it with a newline.  If you try that recipe on
MS-Windows, you see:

  d:\branch\src>od -t x1
  od -t x1
  10000000000 31 30 30 30
  0000004

  d:\branch\src>
  Process shell finished

whereas on GNU/Linux we get the expected:

  $ od -t x1
  10000000000 31 30 30 30
  0000004
  $

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
MS-Windows?

Comments?



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-01-15 10:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-14 12:18 Sending EOF to process as part of comint-simple-send Eli Zaretskii
2023-01-15  5:27 ` Jim Porter
2023-01-15  7:20   ` Eli Zaretskii
2023-01-15  8:40     ` Andreas Schwab
2023-01-15  9:08       ` Eli Zaretskii
2023-01-15 10:08         ` Andreas Schwab
2023-01-15 10:25           ` Eli Zaretskii
2023-01-15 10:32             ` Andreas Schwab
2023-01-15 10:57               ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).