【问题标题】:Get result back from comint-redirect-send-command从 comint-redirect-send-command 返回结果
【发布时间】:2017-07-05 23:01:29
【问题描述】:

我想在 comint 启动的进程完成后读取缓冲区的输出。

(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

此 sexp 在运行 comint 进程的缓冲区中进行评估。一旦过程完成,我想阅读output-buffer-name 的所有文本。

我已尝试应用发布到此问题的解决方案:sleep in emacs lisp,方法是将其添加到进程启动命令下方:

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

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

此消息不会出现在*Messages*

输出缓冲区文本中没有提示,但我可以编写一个函数,根据完整的输出文本在输出完成时返回t

如何对缓冲区完成/更改做出反应,或者如何强制 comint 同步运行此功能。


comint-redirect-send-command-to-process 的来源是here on line 3717

【问题讨论】:

  • comint-redi....函数返回t
  • 您正在为 comint 进程设置哨兵。如果您向该进程发送命令,则不能指望在发送到该进程的下级命令完成时获得 comint 进程哨兵的状态更改。 comint 进程仍在运行。

标签: emacs comint-mode


【解决方案1】:

如果其他人有类似的问题,我最终“解决”了这个问题。

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

comint-redirect-completed 的值为 nil

文档: 如果当前缓冲区中的重定向已完成,则为非 nil。

显然不是一个很好的解决方案,但我无法让其他任何工作。

【讨论】:

  • 也考虑这种模式,来自sql.el:(while (or quit-flag (null comint-redirect-completed)) (accept-process-output nil 1)))
猜你喜欢
  • 1970-01-01
  • 2021-11-10
  • 1970-01-01
  • 1970-01-01
  • 2017-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-08
相关资源
最近更新 更多