(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
DONT-SUPPRESS-ERR is non-nil, stderr won't be sent to /dev/null."
(concat (if subshell "( " "")
(if command (if dont-suppress-err "; " " 2>/tmp/123; ") "")
"echo tramp_exit_status $?"
(if subshell " )" "")))
(with-current-buffer (tramp-get-connection-buffer vec)
(unless (re-search-backward "tramp_exit_status [0-9]+" nil t)
vec 'file-error "Couldn't find exit status of `%s'" command))
(skip-chars-forward "^ ")
(let (buffer-read-only) (delete-region (match-beginning 0) (point-max))))))