Function: artist-system

artist-system is a byte-compiled function defined in artist.el.gz.

Signature

(artist-system PROGRAM STDIN &optional PROGRAM-ARGS)

Documentation

Run PROGRAM synchronously with the contents of string STDIN to stdin.

Optional args PROGRAM-ARGS are arguments to PROGRAM. Return a list (RETURN-CODE STDOUT STDERR).

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/artist.el.gz
(defun artist-system (program stdin &optional program-args)
  "Run PROGRAM synchronously with the contents of string STDIN to stdin.
Optional args PROGRAM-ARGS are arguments to PROGRAM.
Return a list (RETURN-CODE STDOUT STDERR)."
  (save-excursion
    (let* ((tmp-stdin-file-name (if stdin
				    (make-temp-file "artist-stdin.")
				  nil))
	   (tmp-stdout-buffer (get-buffer-create
			       (concat "*artist-" program "*")))
	   (tmp-stderr-file-name (make-temp-file "artist-stdout.")))

      ;; Prepare stdin
      (if stdin (artist-string-to-file stdin tmp-stdin-file-name))

      ;; Clear the buffer
      (artist-clear-buffer tmp-stdout-buffer)

      ;; Start the program
      (unwind-protect
	  (let ((res (if program-args
			 (apply 'call-process
				program
				tmp-stdin-file-name
				(list tmp-stdout-buffer
				      tmp-stderr-file-name)
				nil
				(if (stringp program-args)
				    (list program-args)
				  program-args))
		       (apply 'call-process
			      program
			      tmp-stdin-file-name
			      (list tmp-stdout-buffer
				    tmp-stderr-file-name)
			      nil))))

	    ;; the return value
	    (list res
		  (with-current-buffer tmp-stdout-buffer
                    (buffer-substring (point-min) (point-max)))
		  (artist-file-to-string tmp-stderr-file-name)))

	;; Unwind: remove temporary files and buffers
	(if (and stdin (file-exists-p tmp-stdin-file-name))
	    (delete-file tmp-stdin-file-name))
	(if (file-exists-p tmp-stderr-file-name)
	    (delete-file tmp-stderr-file-name))
	(if (memq tmp-stdout-buffer (buffer-list))
	    (kill-buffer tmp-stdout-buffer))))))