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: Re: How to run shell command with stream input, to get string output Date: Mon, 1 Jul 2019 10:17:16 +0200 Message-ID: <20190701081716.GA11749@protected.rcdrun.com> References: <20190630223205.GA19895@protected.rcdrun.com> <875zomw7cf.fsf@mbork.pl> 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="152336"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) Cc: GNU Emacs Help To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 01 10:17:46 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 1hhrVQ-000dTj-6U for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Jul 2019 10:17:44 +0200 Original-Received: from localhost ([::1]:48568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhrVO-0005cS-Rq for geh-help-gnu-emacs@m.gmane.org; Mon, 01 Jul 2019 04:17:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34765) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhrV3-0005Zu-BL for help-gnu-emacs@gnu.org; Mon, 01 Jul 2019 04:17:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhrV2-0001Jb-42 for help-gnu-emacs@gnu.org; Mon, 01 Jul 2019 04:17:21 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:51583) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhrV1-0001IW-Lv for help-gnu-emacs@gnu.org; Mon, 01 Jul 2019 04:17:19 -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; Mon, 01 Jul 2019 01:17:17 -0700 id 0000000000020354.000000005D19C18D.00007045 Original-Received: from localhost (protected.rcdrun.com [local]) by protected.rcdrun.com (OpenSMTPD) with ESMTPA id c47483f9; Mon, 1 Jul 2019 08:17:16 +0000 (UTC) Content-Disposition: inline In-Reply-To: <875zomw7cf.fsf@mbork.pl> 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:121080 Archived-At: * Marcin Borkowski [2019-07-01 09:22]: > > On 2019-07-01, at 00:32, Jean Louis wrote: > > > 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. > > How about `shell-command-to-string'? That one runs only shell command, without the input. I am looking to something equivalent to shell cat | markdown Hello ===== ## Hello CTRL-D here

Hello

Hello

I have to process thousands of files, I would not like writing to hard disk the feed data for processing to spare the hard disk. As I cannot find solution yet in emacs lisp how to feed some string as input to the shell command, I am using now the virtual memory in /run/user/$UID as this way the hard disk is spared of writing files. It would be ideal if I do not write anything to file system. (defun command-stream-in-out (command string &rest args) (let* ((uid (number-to-string (user-uid))) (xdg-runtime-dir (getenv "XDG_RUNTIME_DIR")) (runtime-dir (concat "/run/user/" uid)) (runtime-dir (if xdg-runtime-dir xdg-runtime-dir runtime-dir)) (infile (concat (slash-add runtime-dir) "markdown-input"))) (string-to-file-force string infile) (with-temp-buffer (apply 'call-process command infile (current-buffer) nil args) (buffer-string)))) Then I can do something like this: (defun markdown (string) (command-stream-in-out "markdown" string)) (defun pandoc-markdown (string) (command-stream-in-out "pandoc" string "-f" "markdown" "-t" "html")) (markdown "Hello\n=============") "

Hello

" (pandoc-markdown "Hello\n=============") "

Hello

" I have solved my problem. But if somebody knows how to feed the string to command as its input, without writing to file system, let me know. Jean