Hello,
I'm currently porting some web apps from Python to Chicken, and really enjoying
the combination of minimalism and expressiveness of Chicken/Scheme.
I'm having trouble interacting with a gnuplot subprocess. Here is an example
Python script that will generate an ugly graph @ /tmp/graph-py.png::
from subprocess import Popen, PIPE
cmd = """
set terminal pngcairo size 460,344 font 'Verdana,10'
set output '/tmp/graph-py.png'
plot '-' using 1:2
2012-09-23 0
2012-09-30 24
2012-10-07 63
"""
def go():
gnuplot = Popen("gnuplot", stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = gnuplot.communicate(cmd + "\nexit")
if err:
# This happens: "Warning: empty x range..." but graph is created.
raise IOError(err)
Here is my attempt to do the same in Chicken::
(use srfi-1 srfi-13 posix extras)
(define cmd "
set terminal pngcairo size 460,344 font 'Verdana,10'
set output '/tmp/graph-scm.png'
plot '-' using 1:2
2012-09-23 0
2012-09-30 24
2012-10-07 63
")
(define go
(lambda ()
(define-values (i o pid stderr) (process* "gnuplot"))
(write-line cmd o)
(write-line "exit" o)
; Hangs trying to read stderr.
(let ((err (read-string #f stderr)))
(if (> (string-length err) 0)
(error err)
(begin
(close-input-port i)
(close-output-port o)
)))))
The Chicken example hangs when I try to read stderr. If I don't attempt to
read the 'o' or 'stderr' ports in the Chicken example, a call to (go) returns,
and the graph is created, but the gnuplot process becomes a zombie.
How can I read the output/err ports without hanging, even if there is no data
on the ports? Also, the docs say that after closing the input/output of a
subprocess, an implicit waitpid happens, so why is gnuplot becoming a zombie?
Bryan
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users