Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs and Long Shell Commands

Tags:

shell

emacs

elisp

Is there a way to run a shell command, have the output show up in a new buffer and have that output show up incrementally? Eshell and other emacs terminal emulators do a find job of this but I see no way to script them.

What I'd like to do is write little elisp functions to do stuff like run unit tests, etc. and watch the output trickle into a buffer.

The elisp function shell-command is close to what I want but it shows all the output at once when the process finishes.

like image 701
darrint Avatar asked Apr 24 '10 21:04

darrint


People also ask

How do I run a shell command in Emacs?

You can execute an external shell command from within Emacs using ` M-! ' ( 'shell-command' ). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size. When used with a prefix argument (e.g, ` C-u M-!

How do I get shells in Emacs?

You can start an interactive shell in Emacs by typing M-x shell . By default, this will start the standard Windows shell cmd.exe . Emacs uses the SHELL environment variable to determine which program to use as the shell.

How do I get rid of half enter commands?

In the docs section Quitting and Aborting: Quitting with 'C-g' is the way to get rid of a partially typed command, or a numeric argument that you don't want.

How do you do commands in Emacs?

The Control key is usually labeled 'Control' or 'CTRL' and is held down while typing the other keys of the command. To enter Emacs, type emacs at the shell prompt. When you want to leave Emacs for a short time, type a C-z and Emacs will be suspended. To get back into Emacs, type %emacs at the shell prompt.


2 Answers

As doublep mentioned, there is M-x compile, and there's also just the simple M-x shell and in that shell you run whatever you want.

like image 177
Trey Jackson Avatar answered Sep 25 '22 15:09

Trey Jackson


You can also use comint-run to execute a command without needing to start a sub-shell first. I believe M-x shell uses comint mode with some modifications, so this won't be a whole lot different from that. But if you want to call a program directly and have its input and output be tied to a buffer, comint-run is the function to call. It is a little tricky to use, so read the documentation: C-h f comint-run.

like image 20
A. Levy Avatar answered Sep 21 '22 15:09

A. Levy