How do I execute a shell-command in background?
Posted
by
Adobe
on Stack Overflow
See other posts from Stack Overflow
or by Adobe
Published on 2012-05-26T13:11:54Z
Indexed on
2012/06/05
10:40 UTC
Read the original article
Hit count: 328
Here's a simple defun to run a shell script:
(defun bk-konsoles ()
"Calls: bk-konsoles.bash"
(interactive)
(shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ")
(if (buffer-file-name)
(file-name-directory (buffer-file-name)))
" &")
nil nil))
If I start a program with no ampersand - it start the script, but blocks emacs until I close the program, if I don't put ampersand it gives error:
/home/boris/its/plts/goodies/bk-konsoles.bash /home/boris/scl/geekgeek/: exited abnormally with code 1.
Edit:
So now I'm using:
(defun bk-konsoles ()
"Calls: bk-konsoles.bash"
(interactive)
(shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ")
(if (buffer-file-name)
(file-name-directory (buffer-file-name)))
" & disown")
nil nil)
(kill-buffer "*Shell Command Output*"))
Edit 2:
Nope - doesn't work:
(defun bk-konsoles ()
"Calls: bk-konsoles.bash"
(interactive)
(let ((curDir default-directory))
;; (shell-command (concat "nohup " (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") curDir) nil nil)
(shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ")
curDir "& disown") nil nil)
(kill-buffer "*Shell Command Output*")))
keeps emacs busy - either with disown
, or nohup
.
Here's a script I'm running if it might be of help: bk-konsoles.bash
© Stack Overflow or respective owner