Re: How to avoid new line from stream

Max Zettlmeißl via clisp-list <[email protected]> Sat, 4 Aug 2018 16:21:57 +0200
Newsgroups gmane.lisp.clisp.general
Message-ID <CACjvM=er+m7-uAr92x6y1EyyoVP0j7xR0NrBFGD=9F-svb1ZZw@mail.gmail.com>
On Sat, Aug 4, 2018 at 12:43 PM, Jean Louis <[email protected]> wrote:
> I just found out it is not handling complex
> commands with arguments like this below. I know
> that run-program requires arguments extra.
>
> (defun gpg-decrypt (string &key homedir)
>   (let ((command
>           (format nil
>                   "gpg -d --no-permission-warning --trust-model always --yes --homedir ~a"
>                   homedir)))
>     (slurp-stream-io-command command string)))
>
> Basically, I am using this one as working:
>
> (defun slurp-stream-io-command (command string)
>   "Returns the output of a command to which string has been fed, very
> usable for markdown, emacs Org mode processing and similar"
>   (with-input-from-string (in string)
>     (uiop:run-program command :input in :output :string :ignore-error-status t)))
>
> however, loading of ASDF and UIOP is taking time,
> which I try to avoid. That is why I am looking
> into pure CLISP way of doing the same.
>
> Do you think I should just take first part before
> space as the command, and arguments as the rest
> and feed to CLISP's run-program?

Yes.

(defun slurp-stream-io-command (command input &key (arguments nil))
  (with-open-stream (stream (run-program command
                                         :arguments arguments
                                         :input :stream
                                         :output :stream))
    (princ input stream)
    (close (two-way-stream-output-stream stream))
    (with-output-to-string (output)
      (loop
         for c = (read-char stream nil)
         while c
         do (write-char c output)))))

(defun gpg-decrypt (string &key homedir)
  (slurp-stream-io-command "gpg"
                           string
                           :arguments (list "-d"
                                            "--no-permission-warning"
                                            "--trust-model" "always"
                                            "--yes"
                                            "--homedir" homedir)))

Although I advise against using "--no-permission-warning" and
"--trust-model always".

And you might want to think about using Emacs Lisp instead of Common
Lisp for the things you are doing,
since that seems to be more fitting so far. It would remove one additional step.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list