From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Sending EOF to process as part of comint-simple-send Date: Sat, 14 Jan 2023 14:18:34 +0200 Message-ID: <83v8l971id.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12599"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Jan 14 13:19:21 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pGfVI-00033n-9B for ged-emacs-devel@m.gmane-mx.org; Sat, 14 Jan 2023 13:19:20 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGfUe-0005FZ-Rb; Sat, 14 Jan 2023 07:18:40 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGfUW-0005FM-La for emacs-devel@gnu.org; Sat, 14 Jan 2023 07:18:32 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGfUW-0006vf-C4 for emacs-devel@gnu.org; Sat, 14 Jan 2023 07:18:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Subject:To:From:Date:mime-version:in-reply-to: references; bh=fmeAlg6bXGTU6OcyRhghZ1Djj3Cb2KNv8nUYOgQalJs=; b=WbxnOR81raP2ML 9XAQzctQWFzZKt6m0us23Khap4xCeO1zeF+0KD4Dk+WwSMtMHL9zWMdZqN3Q+AWvNXzCKK1GNnRbK 1dBQluP5FII7TWSaByOzg4k0TMNfYA6Sq5K29EQwu+0ouyAAz8rkLeHacPCfjaSRgLNBrh24VwM2M bn8ZzAWlGu13tJjEqgQQ9Ee60UobG3iv+faqEBUcWf0HP4lzrZ2t67mduDEmJXvZTeNu9RmHpfGyD jCKoia3NiikHtCGrSX9r5aDCFTPbq+uasJ5EeHBBshw5ONkEWJxxIol4ARfU66fiZNV0w0KC13kVa NeffM24BulFpWFgtmTkQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pGfUV-00026w-Lc for emacs-devel@gnu.org; Sat, 14 Jan 2023 07:18:31 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:302415 Archived-At: 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?