1

I want to run several programs one after another and display their output in a single buffer. I can do this by calling call-process multiple times:

(call-process "cmd1" nil "*out*" t)
(call-process "cmd2" nil "*out*" t)
...

The problem is that Emacs freezes until the last call-process finishes.

How to execute several programs sequentially (one after another) without freezing Emacs?

  • 2
    (1) Asynchronously call a single wrapper process which calls, synchronously, all the child processes. (2) Use process sentinels to kick off each process when the preceding process completes. – phils Mar 3 '16 at 4:21
  • I'd like to avoid (1) if possible. Could you please elaborate a bit about process sentinels? Thanks! – kostya Mar 3 '16 at 4:24
  • 1
    See the manual: C-h i g (elisp) Sentinels – phils Mar 3 '16 at 4:43
  • 1
    lawlist was playing with this kind of thing a while ago, so you can see one approach to the same problem at stackoverflow.com/q/23237869 – phils Mar 3 '16 at 4:51
  • 2
    There is a very well known library called defered that does exactly this. You can find it on melpa or on github: github.com/kiwanami/emacs-deferred. There is a good likelihood that you already have it installed if you are a package junkie – Jules Mar 3 '16 at 21:13
3

You can start with something like:

(let ((proc1 (start-process "myproc1" t "cmd1")))
  (set-process-sentinel proc1
    (lambda (proc1 _string)
      (with-current-buffer (process-buffer proc1)
        (let ((proc2 (start-process "myproc2" t "cmd2")))
          (set-process-sentinel proc2
            (lambda (proc2 _string)
              (with-current-buffer (process-buffer proc2)
                (let ((proc3 (start-process "myproc3" t "cmd3")))
                  ...)))))))))              

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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