(defcustom tramp-shell-prompt-pattern
;; Allow a prompt to start right after a ^M since it indeed would be
;; displayed at the beginning of the line (and Zsh uses it).
- "\\(?:^\\|\r\\)[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
+ "\\(?:^\\|\r\\)[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
"Regexp to match prompts from remote shell.
Normally, Tramp expects you to configure `shell-prompt-pattern'
correctly, but sometimes it happens that you are connecting to a
;; that FILENAME belongs to.
(zerop
(tramp-send-command-and-check
- l (format "cd %s && %s -sf %s %s" cwd ln filename l-localname) t)))))
+ l
+ (format
+ "cd %s && %s -sf %s %s"
+ (tramp-shell-quote-argument cwd)
+ ln
+ (tramp-shell-quote-argument filename)
+ (tramp-shell-quote-argument l-localname))
+ t)))))
(defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
"Like `load' for Tramp files."
;; We found an uncompression rule.
(tramp-message v 0 "Uncompressing %s..." file)
(when (zerop (tramp-send-command-and-check
- v (concat (nth 2 suffix) " " localname)))
+ v (concat (nth 2 suffix) " "
+ (tramp-shell-quote-argument localname))))
(tramp-message v 0 "Uncompressing %s...done" file)
;; `dired-remove-file' is not defined in XEmacs
(funcall (symbol-function 'dired-remove-file) file)
;; Try gzip.
(tramp-message v 0 "Compressing %s..." file)
(when (zerop (tramp-send-command-and-check
- v (concat "gzip -f " localname)))
+ v (concat "gzip -f "
+ (tramp-shell-quote-argument localname))))
(tramp-message v 0 "Compressing %s...done" file)
;; `dired-remove-file' is not defined in XEmacs
(funcall (symbol-function 'dired-remove-file) file)
(string-match "\\`su\\(do\\)?\\'" method))
(setq uname (concat uname user)))
(setq uname
- (with-connection-property v uname
- (tramp-send-command v (format "cd %s; pwd" uname))
- (with-current-buffer (tramp-get-buffer v)
- (goto-char (point-min))
- (buffer-substring (point) (tramp-compat-line-end-position)))))
+ (with-connection-property v uname
+ (tramp-send-command
+ v (format "cd %s; pwd" (tramp-shell-quote-argument uname)))
+ (with-current-buffer (tramp-get-buffer v)
+ (goto-char (point-min))
+ (buffer-substring
+ (point) (tramp-compat-line-end-position)))))
(setq localname (concat uname fname))))
;; There might be a double slash, for example when "~/"
;; expands to "/". Remove this.
(tramp-send-command-and-check
v (format "\\cd %s; %s"
(tramp-shell-quote-argument localname)
- command)))
+ command)
+ nil t))
;; We should show the output anyway.
(when outbuf
(with-current-buffer outbuf
(unless (zerop (tramp-send-command-and-check
vec
(format "echo %s | %s | %s"
- magic rem-enc rem-dec) t))
+ magic rem-enc rem-dec)
+ t))
(throw 'wont-work-remote nil))
(with-current-buffer (tramp-get-buffer vec)
;; Return value is whether end-of-output sentinel was found.
found)))
-(defun tramp-send-command-and-check (vec command &optional subshell)
+(defun tramp-send-command-and-check
+ (vec command &optional subshell dont-suppress-err)
"Run COMMAND and check its exit status.
Sends `echo $?' along with the COMMAND for checking the exit status. If
COMMAND is nil, just sends `echo $?'. Returns the exit status found.
-If the optional argument SUBSHELL is non-nil, the command is executed in
-a subshell, ie surrounded by parentheses."
+If the optional argument SUBSHELL is non-nil, the command is
+executed in a subshell, ie surrounded by parentheses. If
+DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
(tramp-send-command
vec
(concat (if subshell "( " "")
command
- (if command " 2>/dev/null; " "")
+ (if command (if dont-suppress-err "; " " 2>/dev/null; ") "")
"echo tramp_exit_status $?"
- (if subshell " )" " ")))
+ (if subshell " )" "")))
(with-current-buffer (tramp-get-connection-buffer vec)
(goto-char (point-max))
(unless (re-search-backward "tramp_exit_status [0-9]+" nil t)