Re: How to avoid new line from stream
Jean Louis <[email protected]> Mon, 6 Aug 2018 21:30:34 +0200
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Organization | Tanzanite Apollo Limited |
| Message-ID | <[email protected]> |
On Sun, Aug 05, 2018 at 01:49:09PM +0200, Pascal Bourguignon wrote: > > > > On 3 Aug 2018, at 04:25, Jean Louis <[email protected] <mailto:[email protected]>> wrote: > > > > 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? > > The solution is to read clhs. clhs read-line clearly states that read-line returns two values, the second indicating whether a newline has been read or not. If you don’t use this second value, you can’t win. (setq a "line 1 line2 line 3 line 4 ") (read-line (setq in (make-string-input-stream a))) (loop for (line eof) = (multiple-value-list (read-line in nil nil)) while (and line (not eof)) collect line) The above is how I am attempting to solve it. Yet the last line is shown as NIL, T from read-line Is that direction you propose? Jean ------------------------------------------------------------------------------ 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