Function: tramp-smb-handle-process-file

tramp-smb-handle-process-file is a byte-compiled function defined in tramp-smb.el.gz.

Signature

(tramp-smb-handle-process-file PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS)

Documentation

Like process-file for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-smb.el.gz
(defun tramp-smb-handle-process-file
  (program &optional infile destination display &rest args)
  "Like `process-file' for Tramp files."
  (tramp-skeleton-process-file program infile destination display args
    (let ((name
	   (string-replace "*tramp" "*tramp process" (tramp-buffer-name v))))
      ;; Transform input and stderr into a filename powershell does understand.
      (when input
	(setq input
	      (and (not (string-equal input (tramp-get-remote-null-device v)))
		   (format
		    "//%s%s" host (tramp-smb-shell-quote-argument input)))))
      (when stderr
	(setq stderr
	      (and (not (string-equal stderr (tramp-get-remote-null-device v)))
		   (format
		    "//%s%s" host (tramp-smb-shell-quote-argument stderr)))))

      ;; Construct command.
      (setq command (string-join (cons program args) " ")
	    command (if stderr
			(format "%s 2>%s" command stderr)
		      command)
	    command (if input
			(format "Get-Content %s | & %s" input command)
		      command))

      ;; Call it.
      (condition-case nil
	  (with-tramp-saved-connection-properties
	      v '(" process-name" " process-buffer")
	    ;; Set the new process properties.
	    (tramp-set-connection-property v " process-name" name)
	    (tramp-set-connection-property
	     ;; v " process-buffer"
	     ;; (or outbuf (generate-new-buffer tramp-temp-buffer-name)))
	     v " process-buffer" (generate-new-buffer tramp-temp-buffer-name))
	    (with-current-buffer (tramp-get-connection-buffer v)
	      ;; Preserve buffer contents.
	      (narrow-to-region (point-max) (point-max))
	      (tramp-smb-call-winexe v)
	      (tramp-flush-connection-property v " process-exit-status")
	      (tramp-smb-send-command
	       v (format "%s; exit -not $?" command))
	      (while (not (setq ret (tramp-get-connection-property
				     v " process-exit-status")))
		(sleep-for 0.1))
	      (unless (natnump ret) (setq ret 1))
	      ;; We should add the output anyway.
	      (when outbuf
		(with-current-buffer outbuf
		  (insert-buffer-substring (tramp-get-connection-buffer v)))
		(when (and display (get-buffer-window outbuf t)) (redisplay)))))

	;; When the user did interrupt, we should do it also.  We use
	;; return code -1 as marker.
	(quit
	 (kill-buffer (tramp-get-connection-buffer v))
	 (setq ret -1))
	;; Handle errors.
	(error
	 (kill-buffer (tramp-get-connection-buffer v))
	 (setq ret 1))))))