Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you actually want batch processing of <code>stdin</code> and sending the result to <code>stdout</code>, you can use the <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html#Initial-Options" rel="noreferrer">--script</a> command line option to Emacs, which will enable you to write code that reads from <code>stdin</code> and writes to <code>stdout</code> and <code>stderr</code>.</p> <p>Here is an example program which is like <a href="http://en.wikipedia.org/wiki/Cat_%28Unix%29" rel="noreferrer"><code>cat</code></a>, except that it reverses each line:</p> <pre><code>#!/usr/local/bin/emacs --script ;;-*- mode: emacs-lisp;-*- (defun process (string) "just reverse the string" (concat (nreverse (string-to-list string)))) (condition-case nil (let (line) ;; commented out b/c not relevant for `cat`, but potentially useful ;; (princ "argv is ") ;; (princ argv) ;; (princ "\n") ;; (princ "command-line-args is" ) ;; (princ command-line-args) ;; (princ "\n") (while (setq line (read-from-minibuffer "")) (princ (process line)) (princ "\n"))) (error nil)) </code></pre> <p>Now, if you had a file named <code>stuff.txt</code> which contained</p> <pre><code>abcd 1234 xyz </code></pre> <p>And you invoked the shell script written above like so (assuming it is named <code>rcat</code>):</p> <pre><code>rcat &lt; stuff.txt </code></pre> <p>you will see the following printed to stdout:</p> <pre><code>dcba 4321 zyx </code></pre> <p>So, contrary to popular belief, you can actually do batch file processing on <code>stdin</code> and not actually have to read the entire file in at once.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload