Article View: gnu.emacs.help
Article #189368Re: lisp func to return output of shell command
From: Ray Nickson
Date: Fri, 22 Feb 1991 16:56
Date: Fri, 22 Feb 1991 16:56
34 lines
2089 bytes
2089 bytes
In article <1536@umvlsi.ecs.umass.edu> breck@umvlsi.ecs.umass.edu (Liam Breck) writes:
You know the handy system("shell_command_here") call in C that returns
the command's output as a string?
No it doesn't. Perhaps you're thinking of popen(3), which doesn't do
that either. RTFM. :-)
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.
I have tried to find such a thing in Info and by Apropos with every
keyword I could think of (shell, process, exec, system, call, command,
etc.) so if I've missed something, I apologize, but please don't tell
me to RTFM.
I don't think it's there. Try this one:
(defun shell-command-to-string (cmd)
"Run string COMMAND in an inferior shell. Return the output as a string."
(let ((buf (get-buffer-create " *shell-command-to-string temp*")))
(unwind-protect
(progn
(set-buffer buf)
(erase-buffer)
(call-process "sh" nil buf nil "-c" cmd)
(prog1
(buffer-string)
(kill-buffer buf)))
(kill-buffer buf)
nil)))
Improvements or alternatives welcome.
Technical Details
Message-ID:
<NICKSON.91Feb22115657@turakirae.comp.vuw.ac.nz>Path:
arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!cs.utexas.edu!uunet!comp.vuw.ac.nz!nicksonReferences:
<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 14:39:07 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!samsung!cs.utexas.edu!uunet!comp.vuw.ac.nz!nickson From: Ray.Nickson@comp.vuw.ac.nz (Ray Nickson) Newsgroups: gnu.emacs.help Subject: Re: lisp func to return output of shell command Message-ID: <NICKSON.91Feb22115657@turakirae.comp.vuw.ac.nz> Date: 22 Feb 91 16:56:57 GMT References: <1536@umvlsi.ecs.umass.edu> Sender: news@comp.vuw.ac.nz (News Admin) Distribution: gnu Organization: Victoria University of Wellington, Wellington, New Zealand Lines: 34 Nntp-Posting-Host: turakirae.comp.vuw.ac.nz In-Reply-To: breck@umvlsi.ecs.umass.edu's message of 20 Feb 91 21:11:40 GMT