Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs 如何在后台执行shell命令?_Emacs_Elisp - Fatal编程技术网

Emacs 如何在后台执行shell命令?

Emacs 如何在后台执行shell命令?,emacs,elisp,Emacs,Elisp,下面是一个运行shell脚本的简单defun: (defun bk-konsoles () "Calls: bk-konsoles.bash" (interactive) (shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") (if (buffer-file-name)

下面是一个运行shell脚本的简单defun:

(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


下面是我正在运行的脚本,如果它可能有帮助的话:

您可以像这样使用
nohup
disown

$ your_command & disown
$ nohup your_command
有关差异的描述,请参见stackexchange。哦,我解决了这个问题:

(shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ")
                curDir " 2>&1 > /dev/null & disown") nil nil)

我还在bash脚本中使用
2>&1>/dev/null&
调用konsole。默默地工作

我认为问题出在konsole

(shell-command "xterm &")
按照您的期望,在新窗口中打开一个xterm并将控制权返回给Emacs。但是,

(shell-command "konsole &")

立即打开和关闭konsole。konsole的启动方式似乎是问题的根源。我认为KDE应用程序有自己的启动应用程序的系统,但我不确定。无论如何,我认为问题不在Emacs方面。

提示:使用“异步shell命令”instead@kindahero-
async shell命令
如果没有符号,只需在后台添加符号。如果这有效,那么他发布的内容也会有效。你可以像这样使用
disown
your command&diswon
@Daimrod:
your command&diswon
解决它!请给我一个答案,这样我就可以接受了。我想问题出在konsole<代码>(shell命令“x-term&”)执行您期望的操作,但是
(shell命令“konsole&”)会立即打开和关闭konsole。konsole的启动方式似乎是导致问题的原因。酷!看看这个问题的答案。作为旁注,我来这里是因为我只想在emacs缓冲区窗口中运行一个交互式shell,也许其他人也会这么做,在Debian box上安装GNU emacs非常简单:“M-x term”,其中M是alt键。这将通过Emacs缓冲区运行带有输入和输出的子shell。然后可以交互地发出命令。完整的终端仿真是可用的。