Function: tramp-wait-for-output
tramp-wait-for-output is a byte-compiled function defined in
tramp-sh.el.gz.
Signature
(tramp-wait-for-output PROC &optional TIMEOUT)
Documentation
Wait for output from remote command.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-wait-for-output (proc &optional timeout)
"Wait for output from remote command."
(unless (buffer-live-p (process-buffer proc))
(delete-process proc)
(tramp-error proc 'file-error "Process `%s' not available, try again" proc))
(with-current-buffer (process-buffer proc)
(let* (;; Initially, `tramp-end-of-output' is "#$ ". There might
;; be leading escape sequences, which must be ignored.
;; Busyboxes built with the EDITING_ASK_TERMINAL config
;; option send also escape sequences, which must be
;; ignored.
(regexp (format "[^#$\n]*%s\\(%s\\)?\r?$"
(regexp-quote tramp-end-of-output)
tramp-device-escape-sequence-regexp))
;; Sometimes, the commands do not return a newline but a
;; null byte before the shell prompt, for example "git
;; ls-files -c -z ...".
(regexp1 (format "\\(^\\|\000\\)%s" regexp))
(found (tramp-wait-for-regexp proc timeout regexp1)))
(if found
(let ((inhibit-read-only t))
;; A simple-minded busybox has sent " ^H" sequences.
;; Delete them.
(goto-char (point-min))
(when (re-search-forward "^\\(.\b\\)+$" (point-at-eol) t)
(forward-line 1)
(delete-region (point-min) (point)))
;; Delete the prompt.
(when (tramp-search-regexp regexp)
(delete-region (point) (point-max))))
(if timeout
(tramp-error
proc 'file-error
"[[Remote prompt `%s' not found in %d secs]]"
tramp-end-of-output timeout)
(tramp-error
proc 'file-error
"[[Remote prompt `%s' not found]]" tramp-end-of-output)))
;; Return value is whether end-of-output sentinel was found.
found)))