up vote 5 down vote favorite
1
share [g+] share [fb]

With Vim I can easily do

$ echo 123 | vim -

Is it possible to do with Emacs?

$ echo 123 | emacs23
... Emacs starts with a Welcome message

$ echo 123 | emacs23 -
... Emacs starts with an empty *scratch* buffer and “Unknown option”

$ echo 123 | emacs23 --insert -
... “No such file or directory”, empty *scratch* buffer

Is it really impossible to read a buffer from a unix pipe?

Edit: As a solution, I wrote a shell wrapper named emacspipe:

#!/bin/sh
TMP=$(mktemp) && cat > $TMP && emacs23 $TMP ; rm $TMP
link|improve this question
feedback

3 Answers

up vote 4 down vote accepted

Correct, it is impossible to read a buffer from stdin.

The only mention of stdin in the Emacs info pages is this, which says:

In batch mode, Emacs does not display the text being edited, and the standard terminal interrupt characters such as C-z' and C-c' continue to have their normal effect. The functions prin1', princ' and print' output to stdout' instead of the echo area, while message' and error messages output to stderr'. Functions that would normally read from the minibuffer take their input from `stdin' instead.

And the 'read function can read from stdin, but only in batch mode.

So, you can't even work around this by writing custom elisp.

link|improve this answer
Thank you Trey for detailed explanations. – jetxee Aug 31 '09 at 9:10
feedback

offhand, something like:

$ echo 123 > tmp.txt; emacs tmp.txt

or

$ echo 123 > tmp.txt; emacs tmp.txt; rm tmp.txt

is an option. Emacs just doesn't integrate with UNIX the way vim does.

link|improve this answer
It is surprising that Emacs doesn't integrate with UNIX better, given its history and that one of the key tenets of UNIX is that "everything is a file". It feels intuitive to pipe output directly into Emacs. – SabreWolfy Sep 11 '11 at 11:11
feedback

You can redirect to a file, then open the file. e.g.

echo 123 > temp; emacs temp

jweede notes that if you want the temp file to automatically be removed, you can:

echo 123 > temp; emacs temp; rm temp

The Emacsy way to do this is to run the shell command in Emacs.

M-! echo 123 RET

That gives you a buffer named *Shell Command Output* with the results of the command.

link|improve this answer
Yes, I know there is emacsy way, but I hoped it may be used unixy way. Creating a temporary file is not a very nice option (I have to remember to delete it later). – jetxee Aug 31 '09 at 9:08
tacking on ';rm temp' should delete the file once emacs closes – jweede Aug 31 '09 at 12:06
1  
such as: echo 123 > temp; emacs temp; rm temp – jweede Aug 31 '09 at 12:10
1  
In general, there is a high impedance between Emacs and Unix. Or at least between Emacs and the traditional Unix work flow. – Richard Hoskins Aug 31 '09 at 15:28
1  
@jweede If you want to add M-! part of my answer to yours, then I could delete my answer. There is a large overlap in our answers, but I think meta-bang is important to future readers. – Richard Hoskins Aug 31 '09 at 16:03
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.