Emacs组织模式-如何在不挂起Emacs的情况下运行具有后台进程的Shell脚本

巴古尔

将此添加到emacs .org文件中:

#+BEGIN_SRC sh :results verbatim
  #!/bin/bash

  exec 2>&1  # <-- Because Emacs treats stderr output as an error and doesn't show it in the RESULT

  echo before 

  # This nohup should just run in the background and continue to exit
  # the script, but emacs hangs and waits on it anyhow:
  nohup sleep 10 &

  # Failed attempts at working around the hang are:
  #   setsid nohup sleep 10 &
  #   nohup sleep 10 </dev/null & 

  # Do see /tmp/ps.out being updated here so the hang is in Emacs:
  ps -ef --forest --cols=10000 >/tmp/ps.out

  echo after 

  exit 0
#+END_SRC

将点(光标)移动到BEGIN_SRC块中,并使用Cc Cc(绑定到org-ctrl-c-ctrl-c对其进行求值

观察会发生什么。Emacs坐在那里并挂起。我想要它执行的是运行该命令(sleep 10在这个简单的示例中)并继续。

Emacs以某种方式试图等待脚本创建并挂在那里的所有子进程。我必须打Cg才能重新获得控制权。

这种情况的用例是,我想调用一些GUI应用程序(xterm等)并使其在后台运行,但立即将控制权交还给Emacs。

我怎样才能做到这一点?请参阅上面的失败尝试。

编辑:我把问题隔离到最低限度的Emacs Lisp代码。在您的*scratch*(Lisp Interactive)缓冲区中评估以下内容,并观察其挂起3秒钟:

(let ((shell-file-name "/bin/bash")
      (input-file "/tmp/tmpscript.sh")
      (error-file "/tmp/tmperror")
      (shell-command-switch "-c")
      (command "sh")
      exit-status)
  (with-temp-file input-file
    (insert "#!/bin/bash") (newline)
    (insert "nohup sleep 3 &") (newline)
    (insert "exit 0") (newline))
  (setq exit-status
        (apply 'call-process "/bin/bash"
                      input-file
                      (list t error-file)
                      nil
                      (list "-c" "sh"))))

将其更改sleep 3为类似内容sleep 3000,它将挂起3000秒钟,直到您用Cg杀死它为止。

我的emacs版本报告:

GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.4.2) of 2014-09-14 on hungover
沙斯塔

我使用MELPA的ob-async来启用异步执行。

.emacs:

(require 'ob-async)

.org:

#+BEGIN_SRC sh :async
sleep 10 && echo 'Done!'
#+END_SRC

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Emacs组织模式配置

来自分类Dev

Emacs斜体组织模式

来自分类Dev

Emacs Windows组织模式编码

来自分类Dev

Emacs组织模式HTML脚注

来自分类Dev

Emacs组织模式导出减价

来自分类Dev

Emacs Evil <E>模式和组织模式

来自分类Dev

无法在emacs组织模式下打开链接

来自分类Dev

Emacs组织模式下的编号标题

来自分类Dev

在Emacs组织模式下设置个人Wiki

来自分类Dev

Emacs组织模式:执行简单的python代码

来自分类Dev

找不到Emacs组织模式标签

来自分类Dev

emacs时间戳的组织模式语言

来自分类Dev

emacs组织模式文件本地键绑定

来自分类Dev

Emacs组织模式-格式源块

来自分类Dev

Emacs组织模式插入多个图像

来自分类Dev

Emacs组织模式:时钟表配置

来自分类Dev

Emacs组织模式作为工作日记

来自分类Dev

Emacs组织模式捕获,无需扩展

来自分类Dev

Emacs组织模式-格式源块

来自分类Dev

Emacs组织模式插入多个图像

来自分类Dev

将 docx 文件导入 emacs 组织模式

来自分类Dev

如何在Emacs组织模式下选择表的列

来自分类Dev

如何在Emacs的组织模式下插入方括号

来自分类Dev

具有Java语法突出显示功能的Emacs组织模式?

来自分类Dev

Emacs,组织模式,邪恶模式-TAB键不起作用

来自分类Dev

在Emacs的组织模式下关闭矩形标记模式

来自分类Dev

在Emacs的组织模式下关闭矩形标记模式

来自分类Dev

如何在Emacs中阅读组织模式文档?

来自分类Dev

如何在组织模式(emacs)中创建子标题?