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.

  • vfclists@alien.topOPB
    link
    fedilink
    English
    arrow-up
    1
    ·
    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()