From: Teemu Likonen on
Is it possible to read *standard-input* stream as an unsigned byte
stream? Normally it seems to be a character stream.

(stream-element-type *standard-input*)
=> CHARACTER

I'm writing a tool which reads files with '(unsigned-byte 8) as the
element type. When user doesn't give a filename argument the tool reads
standard input instead. I can't figure out how to read it as a stream of
'(unsigned-byte 8) elements. Is this even possible?
From: Alan Malloy on
Teemu Likonen wrote:
> Is it possible to read *standard-input* stream as an unsigned byte
> stream? Normally it seems to be a character stream.
>
> (stream-element-type *standard-input*)
> => CHARACTER
>
> I'm writing a tool which reads files with '(unsigned-byte 8) as the
> element type. When user doesn't give a filename argument the tool reads
> standard input instead. I can't figure out how to read it as a stream of
> '(unsigned-byte 8) elements. Is this even possible?

The open function (and by extension with-open-file) accepts streams
(including open streams) as well as pathnames, and *standard-input* is
an open stream. It seems like you ought to be able to do this via:

(with-open-file (byte-stdin *standard-input* :element-type
'(unsigned-byte 8))
(read-byte byte-stdin))

--
Cheers,
Alan (San Jose, California, USA)
From: joswig on
On 26 Mrz., 21:51, Alan Malloy <alan.NO.S...(a)malloys.org> wrote:
> Teemu Likonen wrote:
> > Is it possible to read *standard-input* stream as an unsigned byte
> > stream? Normally it seems to be a character stream.
>
> >     (stream-element-type *standard-input*)
> >     => CHARACTER
>
> > I'm writing a tool which reads files with '(unsigned-byte 8) as the
> > element type. When user doesn't give a filename argument the tool reads
> > standard input instead. I can't figure out how to read it as a stream of
> > '(unsigned-byte 8) elements. Is this even possible?
>
> The open function (and by extension with-open-file) accepts streams

No, it accepts a 'pathname designator', which can be a stream
associated
with a file.

> (including open streams) as well as pathnames, and *standard-input* is
> an open stream. It seems like you ought to be able to do this via:
>
> (with-open-file (byte-stdin *standard-input* :element-type
>                   '(unsigned-byte 8))
>    (read-byte byte-stdin))

No, that will not work according to the standard. It will also
not create a stream that is connected to another stream.

I don't think this functionality is provided by the standard,
though I'm no expert on this. The usual stream extensions
(gray streams, simple streams, ...) should be able to do this.

From: Teemu Likonen on
* 2010-03-26 14:15 (-0700), joswig(a)lisp.de wrote:

> On 26 Mrz., 21:51, Alan Malloy <alan.NO.S...(a)malloys.org> wrote:
>> (with-open-file (byte-stdin *standard-input* :element-type
>> � � � � � � � � � '(unsigned-byte 8))
>> � �(read-byte byte-stdin))
>
> No, that will not work according to the standard. It will also not
> create a stream that is connected to another stream.
>
> I don't think this functionality is provided by the standard, though
> I'm no expert on this. The usual stream extensions (gray streams,
> simple streams, ...) should be able to do this.

I got a private reply in which I was pointed out that in Unix-like
systems the standard input is also a file. So:

(with-open-file (byte-stdin "/dev/stdin"
:element-type '(unsigned-byte 8))
...)
From: Johan Ur Riise on
Teemu Likonen <tlikonen(a)iki.fi> writes:

> * 2010-03-26 14:15 (-0700), joswig(a)lisp.de wrote:
>
>> On 26 Mrz., 21:51, Alan Malloy <alan.NO.S...(a)malloys.org> wrote:
>>> (with-open-file (byte-stdin *standard-input* :element-type
>>> � � � � � � � � � '(unsigned-byte 8))
>>> � �(read-byte byte-stdin))
>>
>> No, that will not work according to the standard. It will also not
>> create a stream that is connected to another stream.
>>
>> I don't think this functionality is provided by the standard, though
>> I'm no expert on this. The usual stream extensions (gray streams,
>> simple streams, ...) should be able to do this.
>
> I got a private reply in which I was pointed out that in Unix-like
> systems the standard input is also a file. So:
>
> (with-open-file (byte-stdin "/dev/stdin"
> :element-type '(unsigned-byte 8))
> ...)

Thanks
 |  Next  |  Last
Pages: 1 2
Prev: Threading Question
Next: Stop the Heat from Sun Rays!