diff -Naur tramp-orig/lisp/tramp.el tramp/lisp/tramp.el --- tramp-orig/lisp/tramp.el 2006-02-17 21:29:50.000000000 +0100 +++ tramp/lisp/tramp.el 2006-02-18 12:26:10.000000000 +0100 @@ -745,6 +745,26 @@ FUNCTION can also be a customer defined function. For more details see the info pages.") +(defcustom tramp-echo-mark "_end\x08\x08\x08\x08" + "String mark to be transmitted after the end of shell commands +in order to separate their echo from the output they produce. +This will only be used if we cannot disable remote echo via stty. +This string must have no effect on the remote shell except for +producing some echo which can later be detected by +tramp-echoed-echo-mark-regexp. Using some characters followed by an equal +number of backspaces to erase them will usually suffice." + :group 'tramp + :type 'string) + +(defcustom tramp-echoed-echo-mark-regexp "_end\\(\x08 \x08\\)\\{4\\}" + "Regexp which matches tramp-echo-mark as it gets echoed by the remote shell." + :group 'tramp + :type 'regexp) + +(defvar tramp-cannot-disable-remote-echo nil + "True if we can't keep the remote shell from echoing.") + + (eval-after-load "tramp" '(progn (tramp-set-completion-function @@ -5443,6 +5463,14 @@ (tramp-send-command-internal method user host "stty -inlcr -echo kill '^U'") ;; Ignore garbage after stty command. (tramp-send-command-internal method user host "echo foo") + (with-current-buffer (process-buffer p) + (goto-char (point-min)) + (when (looking-at "echo foo") + (setq tramp-cannot-disable-remote-echo t) + (tramp-message 5 "Remote echo still on. Ok.") + ;; make sure backspaces and their echo are enabled and no line + ;; width magic interferes with them + (tramp-send-command-internal method user host "stty sane cols 32767"))) ;; Check whether the remote host suffers from buggy `send-process-string'. ;; This is known for FreeBSD (see comment in `send_process', file process.c). ;; I've tested sending 624 bytes successfully, sending 625 bytes failed. @@ -5760,7 +5788,7 @@ p (processp p) (memq (process-status p) '(run open))) (tramp-send-command method user host "echo are you awake" t t) (unless (and (memq (process-status p) '(run open)) - (tramp-wait-for-output 10)) + (tramp-wait-for-output p 10)) (delete-process p) (setq p nil)))) @@ -5918,6 +5946,8 @@ NOOUTPUT is set." (unless neveropen (tramp-maybe-open-connection method user host)) (set-buffer (tramp-get-buffer method user host)) + (when tramp-cannot-disable-remote-echo + (setq command (format "%s%s" command tramp-echo-mark))) (tramp-message 9 "%s" command) (tramp-send-string method user host command) (unless nooutput @@ -5942,6 +5972,13 @@ (when found (with-current-buffer (process-buffer proc) (let (buffer-read-only) + (when tramp-cannot-disable-remote-echo + ;; discard echo from remote output + (goto-char (point-min)) + (when (re-search-forward tramp-echoed-echo-mark-regexp nil t) + (tramp-message 9 "end-of-echo mark found") + (forward-line) + (delete-region (point-min) (point)))) (goto-char (point-max)) (forward-line -2) (delete-region (point) (point-max))))) @@ -5977,7 +6014,7 @@ (if subshell " )" " "))) (with-current-buffer (tramp-get-connection-buffer method user host) (goto-char (point-max)) - (unless (search-backward "tramp_exit_status " nil t) + (unless (re-search-backward "tramp_exit_status [0-9]+" nil t) (tramp-error method user host 'file-error "Couldn't find exit status of `%s'" command))