Function: tramp-send-command-and-read

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

Signature

(tramp-send-command-and-read VEC COMMAND &optional NOERROR MARKER)

Documentation

Run COMMAND and return the output, which must be a Lisp expression.

If MARKER is a regexp, read the output after that string. In case there is no valid Lisp expression and NOERROR is nil, it raises an error.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-send-command-and-read (vec command &optional noerror marker)
  "Run COMMAND and return the output, which must be a Lisp expression.
If MARKER is a regexp, read the output after that string.
In case there is no valid Lisp expression and NOERROR is nil, it
raises an error."
  (when (if noerror
	    (ignore-errors (tramp-send-command-and-check vec command))
	  (tramp-barf-unless-okay
	   vec command "`%s' returns with error" command))
    (with-current-buffer (tramp-get-connection-buffer vec)
      (goto-char (point-min))
      ;; Read the marker.
      (when (stringp marker)
	(condition-case nil
	    (search-forward-regexp marker)
	  (error (unless noerror
		   (tramp-error
		    vec 'file-error
		    "`%s' does not return the marker `%s': `%s'"
		    command marker (buffer-string))))))
      ;; Read the expression.
      (condition-case nil
	  (prog1
	      (let ((signal-hook-function
		     (unless noerror signal-hook-function)))
		(read (current-buffer)))
	    ;; Error handling.
	    (when (search-forward-regexp (rx (not space)) (line-end-position) t)
	      (error nil)))
	(error (unless noerror
		 (tramp-error
		  vec 'file-error
		  "`%s' does not return a valid Lisp expression: `%s'"
		  command (buffer-string))))))))