I want to call a command asynchronously, and define a function that handles output from that command. I don't want to simply write output to a buffer.
According to the Elisp info (36.9.2 Process Filter Functions) I need to set a process filter function. I tried this:
(defun my-echo-filter (proc string) (message "proc: %s string: %s" proc string)) (let ((my-proc (start-file-process "foo" nil "date"))) (set-process-filter my-proc #'my-echo-filter)) ; writes the time to *Messages*
However, this makes me nervous. I'm starting the process first, and only afterwards am I attaching the process filter.
If I do anything between creating the process and attaching the process filter, I can miss output.
(let ((my-proc (start-file-process "foo" nil "date"))) (sleep-for 2) (set-process-filter my-proc #'my-echo-filter)) ; Does not write the time!
How do I create a process and ensure that my process filter doesn't miss anything?