Historical Perspective

On Unix like operating systems, it is common practice to redirect IO between shell commands using pipes.

For example, the command below would insert all the lines that didn't match "" into the *scratch* buffer in emacs.

 `cat /tmp/ip-addresses.txt | grep -vi "" | emacs --insert /path/to/stdin`

There are numerous ways to do this same task inside of emacs too. One of the easiest methods is probably something like the example below:

M-! cat /tmp/ip-addresses.txt | grep -vi ""

The output from the command would be displayed in new buffer named *Shell Command Output*

One of my favorite features, is to run shell commands asynchronously inside of emacs.

M-& tail -f /tmp/ip-addresses.txt | grep -vi ""

The output from the command would be displayed and be automagically refreshed in new buffer named *Async Shell Command*.


Unfortunately, when I run the asynchronous command outside of emacs the *scratch* buffer will never refresh when the file is updated by another process.

tail -f /tmp/ip-addresses.txt | grep -vi "" | emacs --insert /path/to/stdin


Is there some way to continue reading from a STDIN file descriptor when data is PIPED to Emacs on Command-line?

Note: I'm looking for an answer that shows how to continue reading the redirected IO from the PIPE by modifying the emacs command-line.

For example, to update the destination buffer from *scratch* to a buffer named STDIN I would modify the original command-line like so:

cat /tmp/ip-addresses.txt | grep -vi "" | emacs --eval "(set-buffer (generate-new-buffer \"STDIN\"))" --insert /path/to/stdin

Thanks for your help!

GNU Emacs 24.5.1 (x86_64-unknown-cygwin, GTK+ Version 3.14.13)

  • I have similar need, somehow I missed this question, very well put and still very current. Thanks. – gsl Mar 13 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.