4

I want to read the output of a buffer after process started by comint finishes.

(comint-redirect-send-command-to-process 
                 command-string ;; tested to work in the commint buffer
                 output-buffer-name ;; random text
                 buffer-process ;; (get-buffer-process (current-buffer))
                 nil ;; don't echo input back
                 t) ;; don't show output buffer immediatly

This sexp is evaluated in a buffer running a comint process. I want to read all the text of output-buffer-name once the process has finished.

I have tried applying the solution posted to this question: sleep in emacs lisp by adding this below the process start command:

(defun on-status-change (process status)
        (message "status done"))

(set-process-sentinel buffer-process 'on-status-change)

This message does not appear in *Messages*.

There is no prompt in the output-buffer text, but I can write a function that returns t when the output is finished based on the full output text.

How can I react to the buffer finishing/changing, or how can I force comint to run this function synchronously.


The source for comint-redirect-send-command-to-process is here on line 3717

Karl
  • 427
  • 4
  • 15
  • The comint-redi.... function returns `t` – Karl Jul 06 '17 at 00:11
  • 3
    You're setting a sentinel on the comint process. If you send a command to that process, you can't expect to get a status change for the comint process sentinel at the completion of the inferior command which was sent to that process. The comint process is still running. – phils Jul 06 '17 at 04:52

1 Answers1

2

If anyone else has a similar issue, I ended up "solving" this.

(while (not comint-redirect-completed)
  (sleep-for 0.01))

comint-redirect-completed’s value is nil

Documentation: Non-nil if redirection has completed in the current buffer.

Obviously not a great solution, but I couldn't get anything else working.

Karl
  • 427
  • 4
  • 15
  • 2
    Also consider this pattern, from [sql.el](https://github.com/emacs-mirror/emacs/blob/a1386fa/lisp/progmodes/sql.el#L3988-L3989): ```(while (or quit-flag (null comint-redirect-completed)) (accept-process-output nil 1)))``` – Adam Bliss Sep 04 '19 at 16:11