How can the *shell command output* buffer be kept in the background?

Viewed 3174

How can I tell emacs not to pop up the *Shell Command Output* buffer when calling a shell command like this?

(shell-command MY_COMMAND)

Currently emacs splits the current window into two, showing the (mostly irrelevant) output buffer. To me it would be completely sufficient if I could look it up later if I feel like it.

5 Answers

In my experience, if the shell command itself produces no output, then the emacs *Shell Command Output* buffer won't pop open.

Therefore, to avoid the output buffer, silence the output of the command.

One easy way is:

  • add " > /dev/null 2>&1" to the end of any shell command.

(Caveat: I'm unsure if /dev/null exists on 100% of platforms where one can run emacs, but on every Linux distro it should be fine.)

If the call to elisp function shell-command is in an elisp script, then you could change this:

(shell-command cmd)

to this:

(shell-command (concat cmd " > /dev/null 2>&1"))

If you occasionally do want to monitor the output, then you could create one wrapper function that suppresses the output via /dev/null, and one wrapper function with no suppression, and toggle between them as you wish.

The above advice was tested on: GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2017-09-20 on lcy01-07, modified by Debian

What's even better, is to use

(shell-command (concat cmd " 1>&2") t t)

This way, the output is saved in the error buffer, should you want to look at it. But it does not pop up automatically.

Related