From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: How to run shell command with stream input, to get string output Date: Mon, 1 Jul 2019 00:32:05 +0200 Message-ID: <20190630223205.GA19895@protected.rcdrun.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="12971"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: GNU Emacs Help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 01 00:33:21 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hhiNr-0003GP-MO for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Jul 2019 00:33:19 +0200 Original-Received: from localhost ([::1]:46802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhiNq-00049V-Kw for geh-help-gnu-emacs@m.gmane.org; Sun, 30 Jun 2019 18:33:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55363) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhiNJ-00044h-2X for help-gnu-emacs@gnu.org; Sun, 30 Jun 2019 18:32:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhiNI-0002V7-54 for help-gnu-emacs@gnu.org; Sun, 30 Jun 2019 18:32:44 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:55481) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhiNH-0001vC-UI for help-gnu-emacs@gnu.org; Sun, 30 Jun 2019 18:32:44 -0400 Original-Received: from protected.rcdrun.com (localhost [::1]) (AUTH: PLAIN admin, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA; Sun, 30 Jun 2019 15:32:07 -0700 id 0000000000020357.000000005D193867.0000524E Original-Received: from localhost (protected.rcdrun.com [local]) by protected.rcdrun.com (OpenSMTPD) with ESMTPA id 084c4f9b for ; Sun, 30 Jun 2019 22:32:06 +0000 (UTC) Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.170.207.13 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:121077 Archived-At: Hello, I would like to know how to make in Emacs Lisp the equivalent function to what I have here below in Common Lisp. I wish to feed a string as stream to a command and to get the string output. For example, I would like to do something like this: (setq output (shell-command-feed-string "markdown" "Hello\n=====\n\n")) output would then be something like "

Hello

" so to receive the string back as result from markdown parsing. This type of function then I would use on various commands, not just markdown, but that maybe one good example. I have tried searching for similar in Emacs Lisp manual, could not find it. With CLISP Common Lisp implementation: (defun slurp-stream-io-command2 (command string) "Returns the output of a command to which string has been fed, very usable for markdown, emacs Org mode processing and similar" (let* ((stream (make-pipe-io-stream command :external-format "utf-8")) (in (two-way-stream-input-stream stream)) (out (two-way-stream-output-stream stream)) (result "")) (princ string out) (finish-output out) (close out) (setf result (with-output-to-string (var) (loop for c = (read-char in nil) while c do (format var "~A" c)))) (finish-output in) (close in) (close stream) result)) Thank you, Jean