unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: emacs-devel@gnu.org
Subject: Sending EOF to process as part of comint-simple-send
Date: Sat, 14 Jan 2023 14:18:34 +0200	[thread overview]
Message-ID: <83v8l971id.fsf@gnu.org> (raw)

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?



             reply	other threads:[~2023-01-14 12:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-14 12:18 Eli Zaretskii [this message]
2023-01-15  5:27 ` Sending EOF to process as part of comint-simple-send 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83v8l971id.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).