Subject: Re: How to write binary data to standard out?
From: rpw3@rpw3.org (Rob Warnock)
Date: Mon, 03 Jul 2006 22:01:58 -0500
Newsgroups: comp.lang.lisp
Message-ID: <9_ydnRao3om7RzTZnZ2dnUVZ_radnZ2d@speakeasy.net>
<aaron.brice@gmail.com> wrote:
+---------------
| If I try:
|    (write-byte 128 *standard-output*)
| I get:
|    *** - WRITE-BYTE on #<OUTPUT BUFFERED FILE-STREAM CHARACTER
|    #P"/dev/fd/1"> is illegal
| How can I change the :element-type of *standard-output*?
+---------------

Whether you can at all is implementation-dependent; it may very well
be the case that you can't. However, given that you're obviously
running on a system which supports "/dev/fd/1", why not simply do this?

    (with-open-file (s "/dev/fd/1" :direction :output
				   :if-exists :append
				   :element-type '(unsigned-byte 8))
      (write-byte 128 s))

[Works in CMUCL & CLISP, at least.]


-Rob

p.s. In CMUCL, one could also do it this way:

    (let* ((sym (synonym-stream-symbol *standard-output*))
           (fd1 (system:fd-stream-fd (symbol-value sym)))
           (fd (unix:unix-dup fd1))         ; avoid closing fd1 !!
           (s (system:make-fd-stream fd :output t
                                        :element-type '(unsigned-byte 8))))
      (with-open-stream (s s)
        (write-byte 128 s)))

But that's just UG-lee...  ;-}  ;-}

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607