Xref: utzoo gnu.emacs.help:1318 comp.emacs:10213 Path: utzoo!utgpu!watserv1!watmath!uunet!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage From: aks@ANYWHERE.UCSB.EDU (Alan Stebbens) Newsgroups: gnu.emacs.help,comp.emacs Subject: Re: lisp func to return output of shell command Message-ID: <9103011804.AA13926@anywhere.ucsb.edu> Date: 1 Mar 91 18:04:08 GMT References: <1536@umvlsi.ecs.umass.edu> Sender: daemon@tut.cis.ohio-state.edu Followup-To: gnu.emacs.help Organization: Gatewayed from the GNU Project mailing list help-gnu-emacs@prep.ai.mit.edu Lines: 38 > You know the handy system("shell_command_here") call in C that returns > the command's output as a string? Well I need something like that for > Emacs Lisp... An Emacs function that will execute a a shell command > and return it's output (a short string) which will be bound to a > variable. Try "C-u M-x shell-command-on-region" with the current region being the input, and it will be replaced by the output. Or, you could try the following functions (which haven't been thoroughly tested..) (defun shell-command-to-string (command) "Execute string COMMAND in inferior shell; output is returned as a string." (interactive "sShell command: ") (shell-command-on-region-to-string (point) (point) command)) (defun shell-command-on-region-to-string (start end command) "Execute string COMMAND on current region in inferior shell; output is returned as a string." (interactive "r\nsShell command: ") (let ((buffer (get-buffer-create " *temp Shell Command Output*")) str) (save-excursion (set-buffer buffer) (erase-buffer) (call-process-region start end shell-file-name nil buffer nil "-c" command) (setq str (buffer-string)) (kill-buffer buffer)) str)) Then, to use do, for example: (setq results (shell-command-to-string "ps aux")) Alan