[cmucl-help] Issue with ext:run-program and string streams (related to character sizes?)

Elias Pipping pipping.elias at icloud.com
Mon Aug 1 22:27:51 UTC 2016


Dear list,

I’ve trying to launch an external process and pass input to it from a string.
I’ve ended up with the following code which I think qualifies as a minimal
example if you don’t count the debugging statements:

(let* ((in-string (format nil "A line.~%And another.~%")))
  (with-output-to-string (out-stream nil)
    (with-input-from-string (in-stream in-string)
      (ext:run-program "cat" nil
                       :wait t
                       :input in-stream
                       :output out-stream))
    (let ((out-string (get-output-stream-string out-stream)))
      (format t "Do the lengths match? ~a~%"
              (= (length in-string) (length out-string)))
      (format t "Do the contents match? ~a~%"
              (string= in-string out-string))
      (format t "Type of the in-string: ~a~%" (type-of in-string))
      (format t "Type of the out-string: ~a~%" (type-of out-string))
      (format t "This is what we sent:~%=====~%~a=====~%" in-string)
      (format t "This is what we received:~%=====~%~a=====~%" out-string))))

What it’s supposed to do is pass the string (without the leading whitespace)

  A line.
  And another.

to `cat` and print out the result, which should be the same string. That works for the
most part but not entirely. The output I get is:

  Do the lengths match? T
  Do the contents match? NIL
  Type of the in-string: (SIMPLE-BASE-STRING 21)
  Type of the out-string: (SIMPLE-BASE-STRING 21)
  This is what we sent:
  =====
  A line.
  And another.
  =====
  This is what we received:
  =====
  A li
  And an
  =====

Two lines are received, but only their first half. Indeed, if I make that input lines longer,
the output lines become longer as well. I would assume that this is down to a mix of
character types of different sizes somewhere but I’ve been unable to get this code to
work. So in particular I’m not sure if I’m doing something wrong or if this is a bug in
cmucl (the example works with sbcl and ccl but I might still be doing something wrong).


Elias Pipping

PS: I would’ve opened an issue at

  https://gitlab.common-lisp.net/cmucl/cmucl/issues

but I wasn’t patient enough to wait for an account.


More information about the cmucl-help mailing list