GNU bug report logs -
#34123
A patch to fix reading EOF characters in non-interactive mode
Previous Next
Reported by: Shawn Presser <shawnpresser <at> gmail.com>
Date: Fri, 18 Jan 2019 10:48:02 UTC
Severity: normal
Tags: fixed, patch
Fixed in version 28.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Hello,
Here is a patch to allow batch mode scripts to handle EOF characters. This
solves the following problem:
$ git clone https://github.com/shawwn/y
$ cd y
$ bin/y
> (read t)
Lisp expression: 42
42
> (read t)
Lisp expression: ^Derror: Error reading from stdin
> Error reading from stdin
$
Notice that it’s currently impossible for non-interactive scripts to
recover from EOF when reading from tty. After the user sends an EOF
character by pressing C-d, calling read-from-minibuffer will always result
in an error.
This patch solves this by clearing stdin of errors and returning nil when
an EOF character is detected.
Here is the patch:
From 685452ca4a098bbd7c1062a35064755c1d09512a Mon Sep 17 00:00:00 2001
From: Shawn Presser <shawnpresser <at> gmail.com>
Date: Fri, 18 Jan 2019 03:57:37 -0600
Subject: [PATCH] Fix reading EOF characters in batch mode.
* src/minibuf.c (read_minibuf_noninteractive): Handle EOF characters by
clearing stdin and returning Qnil.
---
src/minibuf.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/minibuf.c b/src/minibuf.c
index 321fda1ba8..8c88a316a7 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -250,7 +250,8 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool
expflag,
else
{
xfree (line);
- error ("Error reading from stdin");
+ clearerr(stdin);
+ return Qnil;
}
/* If Lisp form desired instead of string, parse it. */
--
2.19.1
Thanks!
— shawn
[Message part 2 (text/html, inline)]
[0001-Fix-reading-EOF-characters-in-batch-mode.patch (application/octet-stream, attachment)]
This bug report was last modified 4 years and 338 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.