🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.help
Article #189366

Re: lisp func to return output of shell command

#189366
From: Roger Crew
Date: Thu, 21 Feb 1991 22:07
24 lines
1682 bytes
In article <1536@umvlsi.ecs.umass.edu> breck@umvlsi.ecs.umass.edu (Liam Breck) writes:
> 
> Hi all...
> 
> 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...  


(defun shell-command-to-string (command &optional start end)
  "Execute string COMMAND in inferior shell and return the resulting output
as a string.  Optional second and third arguments specify a region to use
as input to the shell."
  (let ((temp-buffer-show-hook (function ignore)))
    (with-output-to-temp-buffer " *Shell-tmp*"
      (if start
	  (call-process-region start (min (point-max) (or end (point-max)))
			       shell-file-name nil standard-output nil 
			       "-c" command)
	(call-process shell-file-name nil standard-output nil
		      "-c" command))
      (save-excursion
	(set-buffer standard-output)
	(buffer-string)))))
Technical Details
Message-ID: <1991Feb21.220733.23468@Neon.Stanford.EDU>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!shelby!neon!crew
References: <1536@umvlsi.ecs.umass.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103b8b,8812ab3e2fdef023
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 1991-02-22 12:01:18 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!shelby!neon!crew
From: crew@CS.Stanford.EDU (Roger Crew)
Newsgroups: gnu.emacs.help
Subject: Re: lisp func to return output of shell command
Message-ID: <1991Feb21.220733.23468@Neon.Stanford.EDU>
Date: 21 Feb 91 22:07:33 GMT
References: <1536@umvlsi.ecs.umass.edu>
Sender: news@Neon.Stanford.EDU (USENET News System)
Distribution: gnu
Organization: Standard Input
Lines: 24
In-Reply-To: breck@umvlsi.ecs.umass.edu's message of 20 Feb 91 21:11:40 GMT