How can I save the * shell command output buffer in the background?

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

(shell-command MY_COMMAND)

Currently, emacs splits the current window into two, displaying a (mostly irrelevant) output buffer. For me it would be quite enough if I could watch it later if I want.

+7
source share
4 answers

Perhaps use shell-commandwas the root of the problem. I think I found a solution with call-processthat works, although there may be a more elegant way:

(call-process-shell-command
 "cat ~/.emacs.d/init.el"
 nil "*Shell Command Output*" t
 )
+9
source

shell-command OUTPUT-BUFFER, . t ( , nil), . with-temp-buffer :

(with-temp-buffer
  (shell-command "cat ~/.emacs.d/init.el" t))
+9

.

(defun shell-command-as-string (cmd)
  (with-temp-buffer
    (shell-command-on-region (point-min) (point-max)
                             cmd t)
    (buffer-string)))
+1

, , emacs *Shell Command Output* .

, , .

:

  • " >/dev/null 2>&1" .

(: , /dev/null 100% , emacs, Linux .)

elisp function shell-command elisp, :

(shell-command cmd)

:

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

If you sometimes want to control the output, then you can create one wrapper function that suppresses output through /dev/null, and one wrapper function without suppression, and switch between them as you want.

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

0
source

All Articles