1

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?

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.

  • thanks. you mean C-u M-! in that last sentence? – pjc Feb 7 '15 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.