从Emacs运行程序并不等待输出

9
如何让Emacs运行程序并不等待输出或响应?我尝试在外部程序中打开PDF:
(shell-command (concat "start sumatrapdf " (shell-quote-argument path) " -page " search))))

但是在现有的 sumatrapdf 进程关闭之前,它不会打开其他文件。我尝试过使用 async-shell-command ,但它会打开一个新的Async输出缓冲区,而我并不需要这个。

如何正确地在外部程序中打开文件呢?

2个回答

14

start-process 函数可以处理这个:

(start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS)

Start a program in a subprocess.  Return the process object for it.
NAME is name for process.  It is modified if necessary to make it unique.
BUFFER is the buffer (or buffer name) to associate with the process.

Process output (both standard output and standard error streams) goes
at end of BUFFER, unless you specify an output stream or filter
function to handle the output.  BUFFER may also be nil, meaning that
this process is not associated with any buffer.

PROGRAM is the program file name.  It is searched for in `exec-path'
(which see).  If nil, just associate a pty with the buffer.  Remaining
arguments are strings to give program as arguments.

If you want to separate standard output from standard error, invoke
the command through a shell and redirect one of them using the shell
syntax.

如果您不想将缓冲区与打开的进程关联起来-请将nil作为BUFFER参数传递。


谢谢,维克托。在您的提示下,我找到了一个略有不同的函数(start-process-shell-command),因为 start-process 没有正确地接收参数。 - Anton Tarasenko
那么,如何获取BUFFER的末尾并显示它? - zobi8225
start-process 正确地接受了参数。你不需要使用 concat 来处理参数。示例代码如下:(start-process "my-process" "foo" "ls" "-l" "/bin")。更多信息请参见创建异步进程 - azzamsa

4

请查看C-h k M-!

... 如果COMMAND以&结尾,则异步执行它。输出将出现在缓冲区Async Shell Command中。该缓冲区处于shell模式。 ...

也就是说,M-! my_command --opt=foo arg1 arg2 &将启动my_command并创建一个带有my_command运行的*Async Shell Command*缓冲区,但Emacs会立即将控制权交还给您。


1
在我的情况下,Emacs 不应等待任何响应。只需打开文件并忘记它(实际上,这是为了 org-mode 和自定义超链接类型,可以在特定页面打开 PDF)。无论如何,感谢您的关注,Ross。 - Anton Tarasenko

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接