Re: [Chicken-users] Help with usage of process ...

2015-10-10 Thread Matt Welland
On Fri, Oct 9, 2015 at 7:25 PM, Evan Hanson  wrote:

> Hi Matt,
>
> My guess is that because you don't close the output port before waiting
> for results, dot(1) sits there waiting for more input and your procedure
> appears to hang.
>

Ah, yes, dot is not processing the input until it is read in its entirety.
Thanks Evan. The following works fine:

(define (tests:run-dot indat outtype) ;; outtype is plain, fig, dot, etc.
http://www.graphviz.org/content/output-formats
  (let-values (((inp oup pid)(process "dot" (list "-T" outtype
(with-output-to-port oup
  (lambda ()
(map print indat)))
(close-output-port oup)
(let ((res (with-input-from-port inp
 (lambda ()
   (read-lines)
  (close-input-port inp)
res)))



> I'd try closing `oup` once you've written your graph to the process, for
> example by making the thunk you use for the "dot writer" thread look like:
>
> (lambda ()
>   (with-output-to-port oup
>(lambda ()
>  (map print indat)
>  (close-output-port oup
>
> Cheers,
>
> Evan
>
> ___
> Chicken-users mailing list
> Chicken-users@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


Re: [Chicken-users] Help with usage of process ...

2015-10-09 Thread Evan Hanson
Hi Matt,

My guess is that because you don't close the output port before waiting
for results, dot(1) sits there waiting for more input and your procedure
appears to hang.

I'd try closing `oup` once you've written your graph to the process, for
example by making the thunk you use for the "dot writer" thread look like:

(lambda ()
  (with-output-to-port oup
   (lambda ()
 (map print indat)
 (close-output-port oup

Cheers,

Evan

___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users


[Chicken-users] Help with usage of process ...

2015-10-09 Thread Matt Welland
I'm trying to use the posix process call to run the graphviz dot program,
hand it some input data and collect the output. I'm not able to figure out
how to correctly use process to do this. My code is below. Any hints would
be much appreciated.

(define (tests:run-dot indat outtype) ;; outtype is plain, fig, dot, etc.
http://www.graphviz.org/content/output-formats
  (print "indat: ")
  (map print indat)
  (let-values (((inp oup pid)(process "dot" (list "-T" outtype
(let ((th1 (make-thread (lambda ()
  (with-output-to-port oup
(lambda ()
  (map print indat
"dot writer")))
  (thread-start! th1)
  (let ((res (with-input-from-port inp
   (lambda ()
 (read-lines)
(thread-join! th1)
(close-output-port oup)
(close-input-port inp)
;; (process-wait pid)
res)))

For reference this is the equivalent of the following from the commandline:

matt@xena:~/data/megatest/ext-tests$ dot -Tplain << EOF
> digraph tests {
> a -> b
> }
> EOF
graph 1 0.75 1.5
node a 0.375 1.25 0.75 0.5 a solid ellipse black lightgrey
node b 0.375 0.25 0.75 0.5 b solid ellipse black lightgrey
edge a b 4 0.375 0.99579 0.375 0.88865 0.375 0.7599 0.375 0.64045 solid
black
stop
___
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users