Next: , Previous: Expansion, Up: Top

5 Input/Output

Since Eshell does not communicate with a terminal like most command shells, IO is a little different. If you try to run programs from within Eshell that are not line-oriented, such as programs that use ncurses, you will just get garbage output, since the Eshell buffer is not a terminal emulator. Eshell solves this problem by running specified commands in Emacs's terminal emulator; to let Eshell know which commands need to be run in a terminal, add them to the list eshell-visual-commands.

Redirection is mostly the same in Eshell as it is in other command shells. The output redirection operators > and >> as well as pipes are supported, but there is not yet any support for input redirection. Output can also be redirected to Elisp functions, using virtual devices.

eshell-virtual-targets is a list of mappings of virtual device names to functions. Eshell comes with two virtual devices: /dev/kill, which sends the text to the kill ring, and /dev/clip, which sends text to the clipboard.

You can, of course, define your own virtual targets. They are defined by adding a list of the form ("/dev/name" function mode) to eshell-virtual-targets. The first element is the device name; function may be either a lambda or a function name. If mode is nil, then the function is the output function; if it is non-nil, then the function is passed the redirection mode as a symbol–overwrite, append, or insert–and the function is expected to return the output function.

The output function is called once on each line of output until nil is passed, indicating end of output.