🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98410

Re: call-process exit status

#98410
From: Mike Williams
Date: Tue, 06 Aug 1991 14:41
107 lines
5188 bytes
>>> In article <9108021959.AA03452@_next1.osf.org_>,
>>> "macrakis" == macrakis@osf.ORG writes:

macrakis> Is there any way to recuperate the exit status of a process called
macrakis> with call-process?  process-exit-status requires a process object
macrakis> argument, which call-process doesn't give you.  If it weren't
macrakis> incompatible, the obvious solution would be to have call-process
macrakis> return the exit status as its value.  Would this hurt any existing
macrakis> code?

  I believe version 19 will have support for this built-in.  In the
  meantime, you could use the following code as an alternative to
  call-process. 

;; ========================================================================
;; check-process.el -- Function to call a process and return it's exit status
;; Author          : Mike Williams <mike-w@cs.aukuni.ac.nz>
;; Created On      : Thu Jun  6 16:40:00 1991
;; Last Modified By: Mike Williams
;; Last Modified On: Tue Aug  6 10:35:00 1991
;; RCS Info        : $Revision: 1.1 $ $Locker:  $
;; ========================================================================

(defun check-process-region (START END PROGRAM DELETE BUFFER 
				   &optional DISPLAY &rest ARGS)
  "Send text from START to END to a process running PROGRAM.
Delete the text if DELETE is non-nil.
Put output in BUFFER, before point.  nil => discard it, t => current buffer.
Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
Remaining args are passed to PROGRAM at startup as command args.
This function normally waits for the process to terminate;
if you quit, the process is killed.
Upon normal completion, the exit status of the program is returned."
  (let ((delete-exited-processes nil)
	(process-connection-type nil)
	(program (find-exec-command PROGRAM exec-path))
	(out-buffer
	 (cond
	  ((not BUFFER) nil)
	  ((eq BUFFER t) (current-buffer))
	  (t (get-buffer BUFFER))))
	process)
    (if (not (file-name-absolute-p program))
	(error "no such program: %s" PROGRAM))
    (catch 'check-process-exit-status
      (unwind-protect
	  (progn
	    (setq process (apply 'start-process "*check-process*" 
				 out-buffer PROGRAM ARGS))
	    (set-process-sentinel process 'check-process-sentinel)
	    (if DISPLAY
		(set-process-filter process 'check-process-filter))
	    (if (< START END)
		(process-send-region process START END))
	    (if DELETE (delete-region START END))
	    (process-send-eof process)
	    (while (equal (process-status process) 'run)
	      (accept-process-output))
	    (process-exit-status process))
	(delete-process process)))))

(defun check-process-sentinel (PROCESS MESSAGE) 
  (if (not (eq (process-status PROCESS) 'run))
      (throw 'check-process-exit-status (process-exit-status PROCESS))))

(defun check-process-filter (PROCESS STRING) 
  (let ((orig-window (selected-window))
	(pop-up-windows t))
    (unwind-protect 
	(progn
	  (pop-to-buffer (process-buffer PROCESS))
	  (goto-char (point-max))
	  (insert STRING)
	  (set-marker (process-mark PROCESS) (point-max)))
      (select-window orig-window))))

(defun check-process (PROGRAM INFILE BUFFER &optional DISPLAY &rest ARGS)
  "Call PROGRAM in separate process.
Program's input comes from file INFILE (nil means /dev/null).
Insert output in BUFFER before point; t means current buffer;
 nil for BUFFER means discard it.
Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
Remaining arguments are strings passed as command arguments to PROGRAM.
This function waits for PROGRAM to terminate; if you quit,
the process is killed. 
Upon normal completion, the exit status of the program is returned."
  (let ((orig-buffer (current-buffer))
	(out-buffer
	 (cond
	  ((not BUFFER) nil)
	  ((eq BUFFER t) (current-buffer))
	  (t (get-buffer BUFFER))))
	in-buffer)
    (unwind-protect
	(progn
	  (setq in-buffer (get-buffer-create " *check-process input*"))
	  (set-buffer in-buffer) (erase-buffer)
	  (if INFILE (insert-file-contents INFILE))
	  (apply 'check-process-region (point-min) (point-max)
		 PROGRAM 'delete out-buffer DISPLAY ARGS))
      (set-buffer orig-buffer))))

;;=== END of check-process.el =============================================
--
    /-------------------- mike-w@cs.aukuni.ac.nz ---------------------\
    | Mike Williams, Computer Science, Auckland University, Aotearoa. |
    \----------- Death Spasm (The ultimate Ultimate team) ------------/
Technical Details
Message-ID: <MIKE-W.91Aug6104115@cs17.cs.aukuni.ac.nz>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.AUkuni.ac.NZ!mike-w
References: mike-w@cs.AUkuni.ac.NZ (Mike Williams)

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,18a48ef08ef58205
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-08-07 02:26:35 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cs.AUkuni.ac.NZ!mike-w
From: mike-w@cs.AUkuni.ac.NZ (Mike Williams)
Newsgroups: gnu.emacs.bug
Subject: Re: call-process exit status
Message-ID: <MIKE-W.91Aug6104115@cs17.cs.aukuni.ac.nz>
Date: 6 Aug 91 14:41:15 GMT
References: mike-w@cs.AUkuni.ac.NZ (Mike Williams)
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: University of Auckland, New Zealand.
Lines: 107
Approved: bug-gnu-emacs@prep.ai.mit.edu