1

I am writing a lisp program to be run as a batch file through emacs.

The program calls an external application which is supposed to stay running after the call to emacs finishes.

The two basic ways for emacs to call external application that I am aware of are call-process and start-process.

Since call-process creates a synchronous process, it does not meet my requirement to stay alive after the call to emacs is done, so I believe my only alternative is start-process.

However, even though start-process is supposed to create asynchronous processes, it seems like the created process is killed when emacs finishes.

Question. How to start a persistent asynchronous process trough batch in emacs, i.e, one that neither waits for, nor gets killed when emacs finishes?

In the examples below I am using, as external application, the pdf viewer Okular, but you might substitute it for any other GUI application.

;; Does not work because emacs waits for call-process to finish.
SHELL-PROMPT> emacs -Q --batch --eval '(call-process "okular" nil nil nil)'

;; Does not work because emacs apparently kills the created process upon exit
SHELL-PROMPT> emacs -Q --batch --eval '(start-process "Okular" nil "okular")'

;; Here is some more evidence that emacs kills the created process upon exit
SHELL-PROMPT> emacs -Q --batch --eval '(progn (start-process "Okular" nil "okular") (sit-for 3))'

1 Answer 1

3

You can use call-process the same way as you did, but just replace the third argument by 0. If the third argument is 0, Emacs don't wait for the process and quit without killing it.

SHELL-PROMPT> emacs -Q --batch --eval '(call-process "okular" nil 0 nil)'
5
  • Nothing like a short and direct answer! Thanks very much!!! I guess I got confused by the description "Call PROGRAM synchronously in separate process" in the docstring. So in fact it is not synchronous when called with DESTINATION=0, right?
    – Ruy
    May 30, 2021 at 19:38
  • Yes, I agree with you that the description can be a bit misleading. May 31, 2021 at 7:45
  • Dear Nicolas, I just realized that start-process ends up calling another more versatile function named make-process. Would you know how to solve my problem using make-process? That is, adding the appropriate parameters to the following so that the process does not get killed when emacs exits? SHELL-PROMPT> emacs -Q --batch --eval '(make-process :buffer nil :name "OKULAR" :command (list "okular" "file.pdf"))'
    – Ruy
    May 31, 2021 at 14:43
  • I admit that I don't know if this is possible. May 31, 2021 at 21:02
  • Thanks anyways for considering my question. Your help was invaluable to me!
    – Ruy
    Jun 1, 2021 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.