Function: tramp-wait-for-regexp
tramp-wait-for-regexp is a byte-compiled function defined in
tramp.el.gz.
Signature
(tramp-wait-for-regexp PROC TIMEOUT REGEXP)
Documentation
Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
Expects the output of PROC to be sent to the current buffer. Returns the string that matched, or nil. Waits indefinitely if TIMEOUT is nil.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defun tramp-wait-for-regexp (proc timeout regexp)
"Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
Expects the output of PROC to be sent to the current buffer. Returns
the string that matched, or nil. Waits indefinitely if TIMEOUT is
nil."
(let ((found (tramp-check-for-regexp proc regexp)))
(cond (timeout
(with-timeout (timeout)
(while (not found)
(tramp-accept-process-output proc)
(unless (process-live-p proc)
(tramp-error-with-buffer
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))
(t
(while (not found)
(tramp-accept-process-output proc)
(unless (process-live-p proc)
(tramp-error-with-buffer
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))
;; The process could have timed out, for example due to session
;; timeout of sudo. The process buffer does not exist any longer then.
(ignore-errors
(tramp-message
proc 6 "\n%s" (tramp-get-buffer-string (process-buffer proc))))
(unless found
(if timeout
(tramp-error
proc 'file-error "[[Regexp `%s' not found in %d secs]]"
regexp timeout)
(tramp-error proc 'file-error "[[Regexp `%s' not found]]" regexp)))
found))