help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to run shell command with stream input, to get string output


From: Jean Louis
Subject: Re: How to run shell command with stream input, to get string output
Date: Mon, 1 Jul 2019 11:24:00 +0200
User-agent: Mutt/1.10.1 (2018-07-13)

* Marcin Borkowski <mbork@mbork.pl> [2019-07-01 11:14]:
> I'm not sure I get it.
> 
> If you have your data in _files_, why don't you
> 
> (shell-command-to-string "cat <filename> | ...")
> 
> ?

The data is not in files, it is in the database.

My Website Revision System is producing static
HTML pages. Those updates to multiple websites
have thousands and thousands of pages, and if I
would be creating files for each invocation, that
would shorten the life time of a hard disk and
make it slower.

And such easy invokation of shell command with
some input is useful for various other utilities,
for example conversion of coordinates, like here.

(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)

(defun proj/convert-arc1960-to-wgs84 (latitude longitude)
  (let ((string (format "%s %s\n" latitude longitude)))
    (command-stream-in-out "cs2cs" string "-f" "%.5f" "Arc 1960" "WGS84")))

;; (proj/arc1960-wgs84 -1.47666 34.56861)

With result being ("-1.47926" "34.56938" "0.00000")

Imagine having thousands of geographic locations
in the database that require conversion, then for
each would be created one file on hard disk.

Until I learn how to use process-send-string, I am
using memory files in /run/user/$UID

Jean



reply via email to

[Prev in Thread] Current Thread [Next in Thread]