[plt-scheme] Trouble with IO ports
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.
Example:
(require scheme/system)
> (require scheme/system)
> (define p (process "bash"))
> (define ip (car p))
> (define op (cadr p))
> (char-ready? ip)
#f
> (fprintf (cadr p) "ls /")
> (flush-output)
> (char-ready? ip)
#f
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
problem:
(define consume-when-ready
(lambda (ip)
(when input-port-ok?
(let loop ()
(when (not (char-ready? ip))
(loop)))
(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)
(loop)))
(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.
Thanks,
--
Michel Salim