2011-09-04 40 views
5

如何讓Emacs運行程序並不等待輸出/響應?我試圖在外部程序中打開PDF:從Emacs運行程序,不要等待輸出

(shell-command (concat "start sumatrapdf " (shell-quote-argument path) " -page " search)))) 

但直到現有sumatrapdf過程中關閉它不會打開另一個文件。我累async-shell-command,但它打開一個新的緩衝區,我不需要異步輸出。

什麼是正確的方式來在外部程序中的文件?

回答

9

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. 

如果你不想關聯BUFER與開放的過程 - 通過nil緩衝參數

+0

謝謝你,維克多。用你的提示,我發現了一個稍微不同的函數('start-process-shell-command'),因爲'start-process'沒有正確引用參數。 –

+0

那麼,如何讓BUFFER結束並顯示出來呢? – zobi8225

2

C-h k M-!

... 如果COMMAND以&符結束,則異步執行。輸出 出現在緩衝區'異步外殼命令'中。該緩衝區在shell 模式下。 ...

督察,M-! my_command --opt=foo arg1 arg2 &將開始my_command並創建一個*Async Shell Command*緩衝區my_command在它運行,但Emacs會給予控制權交還給你的時候了。

+0

在我的情況下,Emacs不應該等待任何迴應。只需打開一個文件並忘記它(實際上,它是針對組織模式和自定義超鏈接類型的,它將在特定頁面上打開pdf)。無論如何,感謝你的關注,羅斯。 –