2

Looking at the documentation for shell-command (M-!) I see there are two optional arguments, OUTPUT-BUFFER, and ERROR-BUFFER. But when I type M-! it only asks me for the shell command.

How do I supply a value for OUTPUT-BUFFER and ERROR-BUFFER?

clarkep
  • 133
  • 3

1 Answers1

6

Remember that "commands" are just functions, and can be called as such. You can do this:

M-: (shell-command "ls" <arg1here> <arg2here>) RET

If you want to create new buffers, you'll need a bit more lisp.

(shell-command "ls" 
  (generate-new-buffer "ls-stdout") 
  (generate-new-buffer "ls-stderr"))

And if you do this often, you might even make a keybinding:

(defun shell-command-with-buffers (command output-buffer-name error-buffer-name)
  (interactive "Mshell command: \nBoutput buffer name: \nBerror buffer name: ")
  (shell-command command 
    (generate-new-buffer output-buffer-name) 
    (generate-new-buffer error-buffer-name)))

(global-set-key (kbd "C-M-!") #'shell-command-with-buffers)

Also of note, C-u M-! inserts the output and error at the current point.

PythonNut
  • 10,363
  • 2
  • 30
  • 76