unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to run shell command with stream input, to get string output
@ 2019-06-30 22:32 Jean Louis
  2019-07-01  7:18 ` Marcin Borkowski
  0 siblings, 1 reply; 14+ messages in thread
From: Jean Louis @ 2019-06-30 22:32 UTC (permalink / raw)
  To: GNU Emacs Help

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 "<h1>Hello</h1>"

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



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-07-04 20:38 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-30 22:32 How to run shell command with stream input, to get string output Jean Louis
2019-07-01  7:18 ` Marcin Borkowski
2019-07-01  8:17   ` Jean Louis
2019-07-01  8:38     ` tomas
2019-07-01  9:06       ` Jean Louis
2019-07-01  9:38         ` Robert Pluim
2019-07-01  9:43           ` Jean Louis
2019-07-01 11:12             ` Noam Postavsky
2019-07-01 12:15               ` Jean Louis
2019-07-01  9:10     ` Marcin Borkowski
2019-07-01  9:24       ` Jean Louis
2019-07-04 19:16         ` Marcin Borkowski
2019-07-04 20:33           ` Jean Louis
2019-07-04 20:38           ` Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).