4

I want to use async-shell-command to run a .bat file on Windows.
Reading the function documentation it says:

(defun async-shell-command (command &optional output-buffer error-buffer)
  "Execute string COMMAND asynchronously in background.
...
To run COMMAND without displaying the output
in a window you can configure `display-buffer-alist' to use the action
`display-buffer-no-window' for the buffer `*Async Shell Command*'.

Where I mark in bold what I want to achieve: run COMMAND without displaying the output.

So, I guess I need to configure display-buffer-alist variable to use display-buffer-no-window action for *Async Shell Command* buffer. It seems simple...

Checking the display-buffer-alist documentation:

(defcustom display-buffer-alist nil
  "Alist of conditional actions for `display-buffer'.
This is a list of elements (CONDITION . ACTION), where:

 CONDITION is either a regexp matching buffer names, or a
  function that takes two arguments - a buffer name and the
  ACTION argument of `display-buffer' - and returns a boolean.

 ACTION is a cons cell (FUNCTION . ALIST), where FUNCTION is a
  function or a list of functions.  Each such function should
  accept two arguments: a buffer to display and an alist of the
  same form as ALIST.  See `display-buffer' for details.

Well... this is where my head starts to get lost on Emacs/Elisp ecosystem.
Should I do something like this (where I do not know what to put on ???):

(add-to-list 'display-buffer-alist '("*Async Shell Command*" . (display-buffer-no-window . ???)) )

Any help/hints will be appreciated.

2 Answers 2

5

Try this:

(add-to-list 'display-buffer-alist '("*Async Shell Command*" display-buffer-no-window (nil)))

The buffer is still created and it still gets the output of the command (or the error output): it is just not displayed automatically, but you can still get to it to look at what happened with the usual buffer selection mechanisms (C-x b etc).

2
  • Thanks for answering. I haven't tested that one, but just replacing ??? with nil works for me.
    – nephewtom
    May 7, 2020 at 15:36
  • 1
    It does not make much difference in this case: the dotted-pair syntax (a . (b . nil) is equivalent to the list syntax (a b), so you have no placeholder for the "action alist" alluded to in the doc string of display-buffer-alist. The list syntax I used does have such a placeholder and explicitly says that the action alist is empty. In general, it is easier to read list syntax rather than dotted-pair syntax, so if there is a choice you probably want to go with list syntax.
    – NickD
    May 7, 2020 at 16:22
0

Basically I added a nil, instead ??? to my question, and it is working:

(add-to-list 'display-buffer-alist '("*Async Shell Command*" . (display-buffer-no-window . nil)) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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