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: Thu, 4 Jul 2019 22:38:33 +0200 Organization: START YOUR OWN GOLD MINE Message-ID: <20190704203833.GL8543@protected.rcdrun.com> References: <20190630223205.GA19895@protected.rcdrun.com> <875zomw7cf.fsf@mbork.pl> <20190701081716.GA11749@protected.rcdrun.com> <874l46w26t.fsf@mbork.pl> <20190701092400.GF11749@protected.rcdrun.com> <87v9wha9vk.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="35992"; 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 Thu Jul 04 22:39:18 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 1hj8Vh-0009BJ-Oc for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jul 2019 22:39:17 +0200 Original-Received: from localhost ([::1]:48664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj8Va-0004yL-6Y for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jul 2019 16:39:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48235) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hj8V7-0004vU-5z for help-gnu-emacs@gnu.org; Thu, 04 Jul 2019 16:38:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hj8V4-0000KM-V1 for help-gnu-emacs@gnu.org; Thu, 04 Jul 2019 16:38:40 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:51309) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hj8V4-0000Ia-LR for help-gnu-emacs@gnu.org; Thu, 04 Jul 2019 16:38:38 -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; Thu, 04 Jul 2019 13:38:33 -0700 id 0000000000020360.000000005D1E63CA.00007B12 Original-Received: from localhost (protected.rcdrun.com [local]) by protected.rcdrun.com (OpenSMTPD) with ESMTPA id e2078710; Thu, 4 Jul 2019 20:38:33 +0000 (UTC) Content-Disposition: inline In-Reply-To: <87v9wha9vk.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:121101 Archived-At: This is version that I am using now. (defun command-stream (command string &rest args) "Feeds string as input to command" (with-temp-buffer (let* ((process (apply 'start-process "PROCESS" (current-buffer) command args))) (set-process-sentinel process #'ignore) (process-send-string process string) (process-send-eof process) (process-send-eof process) (while (accept-process-output process)) (buffer-string)))) (defun markdown (string) "This is for discount markdown" (command-stream "markdown" string)) (markdown "## Hello") (defun pandoc-markdown (string) (command-stream "pandoc" string "-f" "markdown" "-t" "html")) (pandoc-markdown "## Hello") (defun proj/convert-arc1960-to-wgs84 (latitude longitude) (let ((string (format "%s %s\n" latitude longitude))) (command-stream "cs2cs" string "-f" "%.5f" "Arc 1960" "WGS84"))) (defun proj/arc1960-wgs84 (latitude longitude &optional time height) "Converts single coordinates in DD format from ARC1960 to WGS84 with default height, see https://github.com/OSGeo/proj.4/issues/1110 and https://earth-info.nga.mil/GandG/coordsys/onlinedatum/CountryAfricaTable.html" (let* ((lat-lon (proj/convert-arc1960-to-wgs84 latitude longitude)) (lat-lon (string-trim lat-lon)) (lat-lon (split-string lat-lon)) (latitude (first lat-lon)) (longitude (second lat-lon)) (height (third lat-lon))) (list latitude longitude height))) ;; original point -1.47666 34.56861 ;; geotrans point -1.47927 34.56933 ;; (proj/arc1960-wgs84 -1.47666 34.56861) I call it command-stream, probably is wrong. Jean