unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47299: 27.1; emacs --batch on MS-Windows does not immediately display `print'ed lines when invoked outside of the Command Prompt
@ 2021-03-21 19:45 Ioannis Kappas
  2021-03-21 21:06 ` Ioannis Kappas
  0 siblings, 1 reply; 5+ messages in thread
From: Ioannis Kappas @ 2021-03-21 19:45 UTC (permalink / raw)
  To: 47299


[-- Attachment #1.1: Type: text/plain, Size: 2661 bytes --]

emacs --batch behaves differently on MS-Windows vs. GNU/Linux (at
least) while `print'ing values out, leading to poor user experience
and unexpected behavior.

`print' and its variants (e.g. `prin1' and `princ'), output the printed
representation of an OBJECT passed in as an argument.

A user expects to see `print'ed output from a --batch program as it is
printed out, but output on 'windows-nt when Emacs --batch program is
invoked outside of Command Prompt is only displayed after the
accumulated `print'ed output reaches a certain threshold (4096 bytes)
or the program exits, leading to a poor user experience.

This is unlike the behavior when the program is invoked from the
Command Prompt (output is displayed immediately) or when the program
is invoked from a terminal on 'gnu/linux (output is displayed after a
newline is encountered).

For example, the following is expected to print out immediately a
newline followed by 1 followed by a newline (i.e. "\n1\n"):

: emacs -Q --batch --eval "(progn (princ 1) (sleep-for 5))"

but when invoked from outside the Command Prompt (e.g. M-x shell), the
output is only displayed after 5 seconds (i.e. while the program is
about to exit).

| `system-type' | invoked-from   | result          |
|---------------+----------------+-----------------|
| 'windows-nt   | Command Prompt | immediately     |
| 'windows-nt   | M-x shell      | after 5 seconds |
| 'gnu/linux    | terminal       | immediately     |
| 'gnu/linux    | M-x shell      | immediately     |

Further more, the behavior is even worse when emacs --batch is invoked
programmatically by Emacs itself. If the accumulated `print'ed output
length is relatively small (less than 4096 bytes), no output is
received by the parent Emacs process, unlikely that on 'gnu/linux
where output is received while lines are `print'ed out.

The attached `ert' test demonstrates the above point using `princ',
whereby the parent Emacs process receives the "hi\n" output from the
emacs --batch child process on 'gnu/linux as expected, but it receives
nothing on 'windows-nt.

: emacs -Q --batch -l ert -l batch-print-test.el -f ert-run-tests-batch

| `system-type' | result      |
|---------------+-------------|
| 'windows-nt   | fail        |
| 'gnu/linux    | pass        |

Analysis with likely fixes to follow.

(This report is similar to bug#46388)

Configured using:
 'configure --prefix=/mingw64 --build=x86_64-w64-mingw32 --with-modules
 --without-dbus --without-compress-install 'CFLAGS=-march=x86-64
 -mtune=generic -O2 -pipe' CPPFLAGS=-D__USE_MINGW_ANSI_STDIO=1
 'LDFLAGS=-pipe
 -Wl,--dynamicbase,--high-entropy-va,--nxcompat,--default-image-base-high''

[-- Attachment #1.2: Type: text/html, Size: 3210 bytes --]

[-- Attachment #2: batch-print-test.el --]
[-- Type: application/octet-stream, Size: 1208 bytes --]

;;; -*- lexical-binding: t; -*-
(require 'ert)

(ert-deftest batch-print ()
  "Test that when invoking emacs in batch mode as a
subprocess (i.e. not directly from a terminal), lines printed
with `princ' are flushed to output immediately (i.e. not
buffered)."
  (message ":system %s :version %s" system-configuration emacs-version)

  (let* ((proc-buf (get-buffer-create "issue/batch-print"))

	 ;; start a new emacs process that will print a line to stdout,
	 ;; wait for five second and then exit.
	 (cmd (format "%s -Q --batch --eval=\"%s\""
		      (substring-no-properties (car command-line-args))
		      '(progn (princ \\\"hi\\n\\\")
			 (sit-for 5))))
	 (proc (start-file-process-shell-command
                "test/batch-print" proc-buf cmd))

	 (outputs '()))
    
    ;; capture emacs output
    (set-process-filter proc (lambda (proc output)
			       (push output outputs)))
    
    ;; wait for the process to start
    (sleep-for 2)
    (should (equal 'run (process-status proc)))
    ;; program should have printed out "hi\n"
    (should (equal '("hi\n") outputs))

    ;; kill process and wait for it to die
    (delete-process proc)
    (sleep-for 1)))


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

end of thread, other threads:[~2022-06-26 18:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 19:45 bug#47299: 27.1; emacs --batch on MS-Windows does not immediately display `print'ed lines when invoked outside of the Command Prompt Ioannis Kappas
2021-03-21 21:06 ` Ioannis Kappas
2021-03-23 11:33   ` Eli Zaretskii
2021-03-23 19:05     ` Ioannis Kappas
2022-06-26 18:24       ` Lars Ingebrigtsen

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).