this post was submitted on 25 Oct 2023
1 points (100.0% liked)

Emacs

311 readers
3 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

I want to write a script to process the contents of a text file line by line, and came across this example on Emacs wiki - https://www.emacswiki.org/emacs/BatchMode

emacs --batch --eval "(while t (print (eval (read))))"

So I adjusted it to emacs --batch --eval "(while t (print (read)))" and the prompt Lisp expression: is always displayed.

─○ emacs --batch --eval "(while t (print (read)))" 
Lisp expression: fdfdfds

fdfdfds
Lisp expression: dsfdsfdfds

Lisp expression: ^C%              

When I try a command like cat text1.txt | emacs --batch --eval "(while t (print (read)))" it barfs completely, so read is definitely not the function for this, unless I'm failing to pass some necessary options to it.

top 1 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 1 year ago

I made some progress, with read-from-minibuffer the function I need, however I want to terminate the script and suppress the error information at the end.

─○ cat text1.txt | emacs -batch --eval "(while t (princ (read-from-minibuffer \"\") (terpri)))"

Here is some text
Will it be tripled?

Here is some text
Will it be tripled?

Here is some text
Will it be tripled?
Debugger entered--Lisp error: (end-of-file "Error reading from stdin")
  read-from-minibuffer("")
  (princ (read-from-minibuffer "") (terpri))
  (while t (princ (read-from-minibuffer "") (terpri)))
  eval((while t (princ (read-from-minibuffer "") (terpri))) t)
  command-line-1(("--eval" "(while t (princ (read-from-minibuffer \"\") (terpri)..."))
  command-line()
  normal-top-level()