我想在没有打印其他提示的情况下向comint shell-mode
发送命令。我正在尝试使用comint-redirect-*
API,但我仍然会收到其他提示。什么是一种简单的方法可以完全避免提示打印,或者追踪并删除它?
我的重定向,
(defun my-comint-redirect-silently (proc string)
(let (comint-redirect-perform-sanity-check)
(with-temp-buffer
;; possible to have shell not print prompt?
(comint-redirect-send-command-to-process
string (current-buffer) proc nil 'no-display)))
(with-current-buffer (process-buffer proc)
;; necessary to track back and delete here?
(comint-redirect-cleanup)))
shell-hook中的调用示例
(add-hook 'shell-mode-hook
(lambda ()
(my-comint-redirect-silently
(get-buffer-process (current-buffer)) "TERM=xterm-256color")))
但是,comint shell会打印以下内容(注意双提示)
me@me-M51AC: ~
$ me@me-M51AC: ~
$
不直接相关,但要显示它打印两次,此处的提示设置为
$ echo $PS1
${debian_chroot:+($debian_chroot)}\[\e[32m\]\u@\h: \[\e[33m\]\w\[\e[0m\]\n\$
答案 0 :(得分:2)
我研究了comint-redirect-results-list-from-process的工作方式并提出了建议。
(defun comint-run-thing-process (process command)
"Send COMMAND to PROCESS."
(let ((output-buffer " *Comint Redirect Work Buffer*"))
(with-current-buffer (get-buffer-create output-buffer)
(erase-buffer)
(comint-redirect-send-command-to-process command
output-buffer process nil t)
;; Wait for the process to complete
(set-buffer (process-buffer process))
(while (and (null comint-redirect-completed)
(accept-process-output process)))
;; Collect the output
(set-buffer output-buffer)
(goto-char (point-min))
;; Skip past the command, if it was echoed
(and (looking-at command)
(forward-line))
;; Grab the rest of the buffer
(buffer-substring-no-properties (point) (- (point-max) 1)))))
希望有帮助