Subject: Re: How to write binary data to standard out?
From: (Rob Warnock)
Date: Mon, 03 Jul 2006 22:01:58 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
<> wrote:
| If I try:
|    (write-byte 128 *standard-output*)
| I get:
|    #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.]


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			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607