我试图解决的具体问题是
- 向正在运行的
telnet
session 发送命令 - 使用
消息
回显命令的结果
但普遍的问题是向下级(comint)进程发送命令 等待输出返回并出现新的提示,然后返回输出。
我有:
(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))))))
但是我总是得到的输出是“get_time”,即 Emacs 不等待新的输出。
我从这个 question 得到了 accept-process-output
想法
最佳答案
accept-process-output
在您的情况下返回太早,因为它在接受某些输出后立即返回,但在您的情况下,您希望继续接受输出,直到收到新的提示。请注意,远程进程不会告诉 Emacs“这里有一个提示”,因此您必须调整进程过滤器以识别“哦,我们收到了看起来像提示的内容”,并且您必须调用 accept-process-output
循环直到进程过滤器告诉它(可能通过一些全局变量)它看到了提示。
关于emacs:如何从发送到 comint 缓冲区的命令返回输出(又名劣质进程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15344288/