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.bugs Subject: bug#47299: 27.1; emacs --batch on MS-Windows does not immediately display `print'ed lines when invoked outside of the Command Prompt Date: Tue, 23 Mar 2021 13:33:37 +0200 Message-ID: <837dly85pq.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5108"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 47299@debbugs.gnu.org To: Ioannis Kappas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Mar 23 12:34:33 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1lOfIv-0001CA-9z for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 23 Mar 2021 12:34:33 +0100 Original-Received: from localhost ([::1]:56580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOfIu-00042m-B3 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 23 Mar 2021 07:34:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lOfIQ-000404-Rn for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 07:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lOfIQ-0000oW-J7 for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 07:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lOfIQ-0001y5-GL for bug-gnu-emacs@gnu.org; Tue, 23 Mar 2021 07:34:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 23 Mar 2021 11:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47299 X-GNU-PR-Package: emacs Original-Received: via spool by 47299-submit@debbugs.gnu.org id=B47299.16164992217532 (code B ref 47299); Tue, 23 Mar 2021 11:34:02 +0000 Original-Received: (at 47299) by debbugs.gnu.org; 23 Mar 2021 11:33:41 +0000 Original-Received: from localhost ([127.0.0.1]:59717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOfI4-0001xL-WE for submit@debbugs.gnu.org; Tue, 23 Mar 2021 07:33:41 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:35826) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lOfI1-0001x6-8Z for 47299@debbugs.gnu.org; Tue, 23 Mar 2021 07:33:38 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:52139) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lOfHw-0000bW-0c; Tue, 23 Mar 2021 07:33:32 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1940 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lOfHv-0003qY-CJ; Tue, 23 Mar 2021 07:33:31 -0400 In-Reply-To: (message from Ioannis Kappas on Sun, 21 Mar 2021 21:06:28 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:202893 Archived-At: > From: Ioannis Kappas > Date: Sun, 21 Mar 2021 21:06:28 +0000 > > Similar to bug#46388 (27.1; emacs -batch does not output messages > immediately when invoked outside of the command prompt) the issue > stems from the expectation that stdout buffering should behave like in > POSIX systems, which is not necessarily the case on 'windows-nt. How stdout is buffered when it is not connected to a console device is system-dependent, and any program that relies on a specific buffering has a bug. > stdout on windows-nt is either always unbuffered (when attached to the > console) or fully-buffered (otherwise), while on 'gnu/linux I have > experimentally found it to be line-buffered when invoked from the > terminal or from another program such as Emacs M-x shell. I consider > this line-buffered behavior of 'gnu/linux to fall under the "interactive > device" of the standard mentioned above. > > (When stdout is redirected to a file on 'gnu/linux, I found stdout to > be fully-buffered having a 4096 buffer size). > > (See standard-streams-test report @ > https://github.com/ikappaki/standard-streams-test for a tool that was > written to investigate the buffering behavior of stderr on MS-Windows, > i.e. unbuffered when attached to console, fully buffered > otherwise. The same tool was modified to test stdout on a similar > manner, which yielded exactly the same result). > > Thus the difference in behavior as described in the bug report is due > to stdout on 'windows-nt being fully buffered, rather than being line > buffered as in 'gnu/linux. The difference you observe is because on Windows we use pipes to communicate with subprocesses, while on Posix platforms we by default use PTYs, which are a kind of console device. You can try using pipes on GNU/Linux (by setting the process-connection-type variable), and you will then see that the behavior on these two systems is similar, not different. > As such, two likely fixes are presented below, one that flushes stdout > on a newline only iff stdout is attached to a pipe (as if it is the > "interactive device" of the POSIX standard) but staying fully buffered > otherwise (e.g. when output was redirected to a pipe or a socket), while > the other fix always flushing stdout on a newline (a much simpler and less > involved solution -- similar to the one in bug#46388 suggested by Mr. Eggert > -- though not optimized for redirections to files). I'm against both these changes. Unconditionally flushing stdout each newline is a non-starter, because it will slow down Lisp programs that aren't interactive and need to send large buffers both ways. At this low level it cannot be known whether "the other end" of the pipe expects interactivity or not. What I can offer is to add a Lisp function to flush the stdout stream. Lisp programs that need to provide interactive experience could call that function where appropriate. I don't see any other solution; doing what we do with stderr is certainly inappropriate. Thanks.