How to avoid new line from stream

Jean Louis <[email protected]> Fri, 3 Aug 2018 04:25:53 +0200
Newsgroups gmane.lisp.clisp.general
Message-ID <[email protected]>
Hello,

I am trying to solve the problem here that if
there is no ending newline, my function is still
printing it.

(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 (format nil "~{~A~%~}" (loop for line = (read-line in nil)
					 while line
					 collect line)))
    ;; (setf result (with-output-to-string (var)
    ;; 		   (loop for line = (read-line in nil :eof)
    ;; 		      until (eq line :eof)
    ;; 		      do (format var "~A~%" line))))
    (finish-output in)
    (close in)
    (close stream)
    result))

(setf message "something")
(slurp-stream-io-command2 "cat" message)

"something
"

while I would need "something" as result. Somebody knows solution?


-- 
Jean Louis

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