event_jr
event_jr

Reputation: 17707

emacs: How to return output from command sent to comint buffer (aka inferior process)

The specific problem I'm trying to solve is

  1. send a command to a running telnet session
  2. echo the result of the command with message

But the general problem is sending a command to an inferior (comint) process and waiting for output to come back and a new prompt to appear, and return the output.

I have:

(defun dired-vlc-test ()
  (interactive)
  (let* ((buf (process-buffer dired-vlc-telnet-proc))
         (old-max (with-current-buffer buf
                    (point-max))))
    (telnet-simple-send dired-vlc-telnet-proc "get_time")
    (accept-process-output dired-vlc-telnet-proc 5)
    (message (buffer-substring-no-properties old-max (with-current-buffer buf
                                                       (point-max))))))

However the output I always get is "get_time", i.e. Emacs is not waiting for new output.

I got the accept-process-output idea from this question

Upvotes: 2

Views: 820

Answers (1)

Stefan
Stefan

Reputation: 28541

accept-process-output returns too early in your case because it returns as soon as it has accepted some output, but in your case you want to keep accepting output until you get a new prompt. Notice that the remote process does not tell Emacs "here's a prompt", so you will have to tweak your process filter to recognize "Oh, we received something that looks like a prompt" and you will have to call accept-process-output in a loop until the process filter tells it (via some global variable, probably) that it has seen a prompt.

Upvotes: 3

Related Questions