作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将此添加到 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
org-ctrl-c-ctrl-c
)对其进行评估。
sleep 10
在这个简单的例子中)并继续。
*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 秒,直到你用 C-g 杀死它。
GNU Emacs 24.4.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.4.2) of 2014-09-14 on hungover
最佳答案
我用 ob-async从 MELPA 启用异步执行。
.emacs:
(require 'ob-async)
#+BEGIN_SRC sh :async
sleep 10 && echo 'Done!'
#+END_SRC
关于Emacs org-mode - 如何在不挂起 Emacs 的情况下使用后台进程运行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835337/
我是一名优秀的程序员,十分优秀!