下面是一個簡單defun定義運行shell腳本:如何在後臺執行shell命令?
(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))
如果我啓動一個程序,沒有符號 - 它啓動腳本,但塊的emacs,直到我關閉程序,如果我不把&符號提示錯誤:
/home/boris/its/plts/goodies/bk-konsoles.bash /home/boris/scl/geekgeek/: exited abnormally with code 1.
編輯:
所以,現在我使用的是:
(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*"))
編輯2:
都能跟得上 - 不工作:
(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*")))
保持emacs的忙 - 要麼disown
,或nohup
。
這裏是我跑,如果它可能會有所幫助的腳本:bk-konsoles.bash
提示:使用'async-shell-command'代替 – kindahero
@kindahero - 'async-shell-command'只是在場景後面添加&符號。如果這有效,那麼他發佈的內容也會起作用。 – Inaimathi
你可以像這樣使用'disown':'your-command&diswon'。 – Daimrod