[plt-scheme] null-port ? and system*/exit-code

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sun Mar 11 06:21:01 EDT 2007

Eli Barzilay skrev:
> On Mar 10, Paulo J. Matos wrote:
>> [...]
>> Any ideas on how to define a null-port or ignore output from command
>> in system*/exit-port?
> 
> You can use `open-output-nowhere', or you can just use
> 
>   (open-output-file "/dev/null" 'append)
> 

Section 11.1 om custom ports in the MzScheme manual has the following
example:

;; A port that writes anything to nowhere:
(define /dev/null-out
   (make-output-port
    'null
    always-evt
    (lambda (s start end non-block? breakable?) (- end start))
    void
    (lambda (special non-block? breakable?) #t)
    (lambda (s start end) (wrap-evt
                           always-evt
                           (lambda (x)
                             (- end start))))
    (lambda (special) always-evt)))

(display "hello" /dev/null-out)            ; => void
(write-bytes-avail #"hello" /dev/null-out) ; => 5
(write-special 'hello /dev/null-out)       ; => #t
(sync (write-bytes-avail-evt #"hello" /dev/null-out)) ; => 5


That will work on Windows too.

-- 
Jens Axel Søgaard



Posted on the users mailing list.