Prev: Threading Question
Next: Stop the Heat from Sun Rays!
From: Johan Ur Riise on 27 Mar 2010 05:28 Johan Ur Riise <johan(a)riise-data.no> writes: > Teemu Likonen <tlikonen(a)iki.fi> writes: >> 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 Ignore, I was too quick.
From: Johan Ur Riise on 27 Mar 2010 06:55 Teemu Likonen <tlikonen(a)iki.fi> writes: Inspired by 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: for Steel Bank Common Lisp start of file br.lisp (deftype octet () '(unsigned-byte 8)) (let ((stdin (sb-sys:make-fd-stream 0 :name "standard input" :input t :buffering :full :element-type 'octet))) (handler-case (loop do (format t "~2,'0X~%" (read-byte stdin))) (end-of-file (c) (format t "I got end of file on my special standard input: ~a~%" c)))) end of file br.lisp and command sbcl --script br.lisp in my utf-8 terminal, typing the character � (which is represented as two bytes in utf-8) and a carriage return, and control-D produces this: johan(a)perle:~/prg/bytestream$ sbcl --script br.lisp � C3 A6 0A I got end of file on my special standard input: end of file on #<SB-SYS:FD-STREAM for "standard input" {1002CC6D51}> johan(a)perle:~/prg/bytestream$ johan(a)perle:~/prg/bytestream$ sbcl --script br.lisp < /bin/ls works as expected. Does not work in slime.
From: nikodemus on 28 Mar 2010 09:26 On Mar 27, 1:55 pm, Johan Ur Riise <jo...(a)riise-data.no> wrote: > for Steel Bank Common Lisp If you use bleeding edge SBCL (1.0.37.3 or newer), *STANDARD-INPUT*, *STANDARD-OUTPUT*, and *ERROR-OUTPUT* are bivalent, so you can use both READ-BYTE and READ-CHAR on them directly. Cheers, -- Nikodemus
From: Johan Ur Riise on 28 Mar 2010 10:54
nikodemus <nikodemus.siivola(a)gmail.com> writes: > If you use bleeding edge SBCL (1.0.37.3 or newer), *STANDARD-INPUT*, > *STANDARD-OUTPUT*, and *ERROR-OUTPUT* are bivalent, so you can use > both READ-BYTE and READ-CHAR on them directly. > Nice. My previous sbcl was only 3 days old. |