(define pipe-path "/tmp/named-pipes-test") (when (file-exists? pipe-path) (delete-file pipe-path)) (create-pipe pipe-path 0777) (define input (open-input-pipe pipe-path)) (define output (open-output-pipe pipe-path)) (display "Bytes: ") (newline) (define bytes '(1 2 3 4 5 6 7 8)) (for-each (lambda (item) (pipe-write-u8 item output)) bytes) (for-each (lambda (item) (let ((output (pipe-read-u8 input))) (if (= output item) (begin (display "Wrote: ") (write item) (newline) (display "Read: ") (write output) (newline)) (error "Bytes do not match" (list item output))))) bytes) (display "Chars: ") (newline) (define chars (string->list "Hello world")) (for-each (lambda (item) (pipe-write-char item output)) chars) (for-each (lambda (item) (let ((output (pipe-read-char input))) (if (char=? output item) (begin (display "Wrote: ") (write item) (newline) (display "Read: ") (write output) (newline)) (error "Chars do not match" (list item output))))) chars) (display "String: ") (newline) (define text "Hello world") (pipe-write-string text output) (define output-string (pipe-read-string (string-length text) input)) (if (string=? output-string text) (begin (display "Wrote: ") (write text) (newline) (display "Read: ") (write output-string) (newline)) (error "String does not match" (list text output-string))) (display "Line: ") (newline) (define should-be-eof (pipe-read-line input)) (when (not (eof-object? should-be-eof)) (error "Reading line from empty buffer should eof" should-be-eof)) (define line (string-append "Hello world" (string #\newline))) (define expected-output-line "Hello world") (pipe-write-string line output) (define output-line (pipe-read-line input)) (if (string=? output-line expected-output-line) (begin (display "Wrote: ") (write line) (newline) (display "Read: ") (write output-line) (newline)) (error "String does not match" (list expected-output-line output-line))) (display "Read: ") (newline) (set! should-be-eof (pipe-read input)) (when (not (eof-object? should-be-eof)) (error "Reading from empty buffer should eof" should-be-eof)) (define text1 (string-append "Hello world" (string #\newline))) (pipe-write-string text1 output) (define output-text1 (pipe-read input)) (if (string=? output-text1 text1) (begin (display "Wrote: ") (write text1) (newline) (display "Read: ") (write output-text1) (newline)) (error "String does not match" (list text1 output-text1))) (when (file-exists? pipe-path) (delete-file pipe-path))