(defun async-shell-command (command &optional output-buffer error-buffer)
"Execute string COMMAND asynchronously in background.
Like `shell-command', but adds `&' at the end of COMMAND
to execute it asynchronously.
The output appears in the buffer whose name is stored in the
variable `shell-command-buffer-name-async'. That buffer is in
shell mode.
You can configure `async-shell-command-buffer' to specify what to do
when the buffer specified by `shell-command-buffer-name-async' is
already taken by another running shell command.
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 given by
`shell-command-buffer-name-async'.
In Elisp, you will often be better served by calling `start-process'
directly, since it offers more control and does not impose the use of
a shell (with its need to quote arguments)."
(interactive
(list
(read-shell-command (if shell-command-prompt-show-cwd
(format-message "Async shell command in `%s': "
(abbreviate-file-name
default-directory))
"Async shell command: ")
nil nil
(let ((filename
(cond
(buffer-file-name)
((eq major-mode 'dired-mode)
(dired-get-filename nil t)))))
(and filename (file-relative-name filename))))
current-prefix-arg
shell-command-default-error-buffer))
(unless (string-match "&[ \t]*\\'" command)
(setq command (concat command " &")))
(shell-command command output-buffer error-buffer))