title: Reading the binary output of an external program in Common Lisp
body: <p>I'm trying to run an external program in SBCL and capture its output.
  The output is binary data (a png image), while SBCL insists on interpreting it as strings.</p>
  
  <p>I tried a number of ways, like</p>
  
  <pre><code>(trivial-shell:shell-command "/path/to/png-generator" :input "some input")
  
  (with-input-from-string (input "some input")
    (with-output-to-string (output)
      (run-program "/path/to/png-generator" () :input input :output output))
  
  
  (with-input-from-string (input "some input")
    (flexi-streams:with-output-to-sequence (output)
      (run-program "/path/to/png-generator" () :input input :output output))
  </code></pre>
  
  <p>But I get errors like</p>
  
  <pre><code>Illegal :UTF-8 character starting at byte position 0.
  </code></pre>
  
  <p>It seems to me that SBCL is trying to interpret the binary data as a text and decode it. How do I change this behaviour ? I'm interested only in obtaining a vector of octets.</p>
  
  <p>Edit: Since it is not clear from the text above, I'd like to add that at least in the case of flexi-stream, the element-type of the stream is a <code>flexi-streams:octect</code> (which is a <code>(unsigned-byte 8)</code>).
  I would expect at least in this case <code>run-program</code> to read the raw bytes without many issues. Instead I get a message like <code>Don't know how to copy to stream of element-type (UNSIGNED-BYTE 8)</code></p>