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."
  (tramp-send-command
   vec
   (concat (if subshell "( " "")
	   command
	   (if command
               (if dont-suppress-err
                   "; " (format " 2>%s; " (tramp-get-remote-null-device vec)))
             "")
	   "echo tramp_exit_status $?"
	   (if subshell " )" "")))
  (with-current-buffer (tramp-get-connection-buffer vec)
    (unless (tramp-search-regexp "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))))))