Function: tramp-send-command-and-check

tramp-send-command-and-check is a byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-send-command-and-check VEC COMMAND &optional SUBSHELL DONT-SUPPRESS-ERR EXIT-STATUS)

Documentation

Run COMMAND and check its exit status.

Send echo $? along with the COMMAND for checking the exit status. If COMMAND is nil, just send echo $?. Return t if the exit status is 0, and nil otherwise.

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". Optional argument EXIT-STATUS, if non-nil, triggers the return of the exit status.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-send-command-and-check
  (vec command &optional subshell dont-suppress-err exit-status)
  "Run COMMAND and check its exit status.
Send `echo $?' along with the COMMAND for checking the exit status.
If COMMAND is nil, just send `echo $?'.  Return t if the exit
status is 0, and nil otherwise.

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\".
Optional argument EXIT-STATUS, if non-nil, triggers the return of
the exit status."
  (let (cmd data)
    (if (and (stringp command)
	     (string-match
	      (tramp-compat-rx
	       (* nonl) "<<'" (literal tramp-end-of-heredoc) "'" (* nonl))
	      command))
	(setq cmd (match-string 0 command)
	      data (substring command (match-end 0)))
      (setq cmd command))
    (tramp-send-command
     vec
     (concat (if subshell "( " "")
	     cmd
	     (if cmd
		 (if dont-suppress-err
                     "; " (format " 2>%s; " (tramp-get-remote-null-device vec)))
               "")
	     "echo tramp_exit_status $?"
	     (if subshell " )" "")
	     data)))
  (with-current-buffer (tramp-get-connection-buffer vec)
    (unless (tramp-search-regexp (rx "tramp_exit_status " (+ digit)))
      (tramp-error
       vec 'file-error "Couldn't find exit status of `%s'" command))
    (skip-chars-forward "^ ")
    (prog1
	(if exit-status
	    (read (current-buffer))
	  (zerop (read (current-buffer))))
      (let ((inhibit-read-only t))
	(delete-region (match-beginning 0) (point-max))))))