Xref: utzoo gnu.emacs.help:1323 comp.emacs:10220 Path: utzoo!utgpu!watserv1!watmath!uunet!shelby!agate!usenet.ins.cwru.edu!mcs.kent.edu!VAX1.CC.UAKRON.EDU!tut.cis.ohio-state.edu!unreplyable!garbage From: allen@NERD.SSC.GOV (Mike Allen) Newsgroups: gnu.emacs.help,comp.emacs Subject: lisp func to return output of shell command Message-ID: <9103011352.AA09307@life.ai.mit.edu> Date: 1 Mar 91 13:49:12 GMT References: <1536@umvlsi.ecs.umass.edu> Sender: daemon@tut.cis.ohio-state.edu Reply-To: allen@sscvx1.ssc.gov Followup-To: gnu.emacs.help Organization: Gatewayed from the GNU Project mailing list help-gnu-emacs@prep.ai.mit.edu Lines: 62 >>>>> On 20 Feb 91 21:11:40 GMT, samsung!crackers!m2c!umvlsi!umvlsi.ecs.umass.edu@uunet.uu.net (Liam Breck) said: Liam> Resent-Date: 20 Feb 91 21:11:40 GMT Liam> Resent-From: gnulists@ai.mit.edu Liam> Hi all... Liam> You know the handy system("shell_command_here") call in C that returns Liam> the command's output as a string? Well I need something like that for Liam> Emacs Lisp... An Emacs function that will execute a a shell command Liam> and return it's output (a short string) which will be bound to a Liam> variable. Liam> I have tried to find such a thing in Info and by Apropos with every Liam> keyword I could think of (shell, process, exec, system, call, command, Liam> etc.) so if I've missed something, I apologize, but please don't tell Liam> me to RTFM. I suggest you get the lisp manual, there is a whole chapter on using processes from emacs lisp. Here is an excerpt that discusses what you want to do (I think): * Function: process-filter PROCESS This function returns the filter function of PROCESS, or `nil' if it has none. Here is an example of use of a filter function: (defun keep-output (process output) (setq kept (cons output kept))) => keep-output (setq kept nil) => nil (set-process-filter (get-process "shell") 'keep-output) => keep-output (process-send-string "shell" "ls ~/other\n") => nil kept => ("lewis@slug[8] % " "FINAL-W87-SHORT.MSS backup.otl kolstad.mss~ address.txt backup.psf kolstad.psf backup.bib~ david.mss resume-Dec-86.mss~ backup.err david.psf resume-Dec.psf backup.mss dland syllabus.mss " "#backups.mss# backup.mss~ kolstad.mss ") Here is another, more realistic example, which demonstrates how to use the process mark to do insertion in the same fashion as is done when there is no filter function: ;; Insert input in the buffer specified by `my-shell-buffer' ;; and make sure that buffer is shown in some window. (defun my-process-filter (proc str) (let ((cur (selected-window)) (pop-up-windows t)) (pop-to-buffer my-shell-buffer) (goto-char (point-max)) (insert str) (set-marker (process-mark proc) (point-max)) (select-window cur)))