[plt-scheme] Trouble with IO ports

From: Michel S. (michel.sylvan at gmail.com)
Date: Sun Feb 8 16:39:02 EST 2009

Using PLT 4.1.4 (the Fedora 9/i386 from plt-scheme.org), when creating
a process, the input port appears to never contain anything.


(require scheme/system)
> (require scheme/system)
> (define p (process "bash"))
> (define ip (car p))
> (define op (cadr p))
> (char-ready? ip)
> (fprintf (cadr p) "ls /")
> (flush-output)
> (char-ready? ip)

On Windows, the problem appears to be worse -- in Unix, this works:
> (fprintf (cadr p) "echo foo > foo.txt")
> (flush-output)

whereas in Windows (using cmd instead of bash), nothing is written.

On the other hand, on Windows, the input port initially contains some
data, and the following code will retrieve the data without any

(define consume-when-ready
  (lambda (ip)
    (when input-port-ok?
      (let loop ()
        (when (not (char-ready? ip))
      (let ([outs (open-output-string)])
        (let loop ()
          (when (or (char-ready? ip)
                    (begin ;; allow for slow responses
                      (sleep 0.1)
                      (char-ready? ip)))
            (write-char (read-char ip) outs)
        (get-output-string outs)))))

I'm writing an interface from Scheme to Python, using process pipes to
communicate between the two, so bidirectional communication is rather
important. Any idea why this bizarre behavior occurs?

(on Chez Scheme, in Unix -- Linux and OS X -- everything works; on
Windows, the output works but the input is even more dangerous -- char-
ready? will erroneously return #t but the interpreter enters an
infinite loop when (read-char ip) is attempted.


Michel Salim

Posted on the users mailing list.