Thanks Eli - please see inline. <br><br><div class="gmail_quote">On Mon, Jun 16, 2008 at 10:40 PM, Eli Barzilay <<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><br></div>You have the rough idea, but several problems:<br>
<br>
* you have a redundant `lambda' which means that you never really get<br>
to read anything (on toy examples, this will probably be a change<br>
that will make things work, but see below)<br>
</blockquote><div><br>Yup - it worked after removing the lambda. <br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
* `write' is probably not a good idea -- it will print something with<br>
the double quotes.<br></blockquote><div><br>Makes sense. <br><br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
* after you write, you'd want to flush `pin', or if you expect the<br>
program to get just that, then you'd want to close it (so your<br>
program will not sit there waiting for more stuff)<br>
</blockquote><div><br>Ah ha! I first tried to write eof to the stream and it didn't work... thanks for the pointer! <br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
* finally, the biggest problem is a conceptual one: you read stuff<br>
from the output only after the process has finished -- but what if<br>
it spits out a lot of data? In that case, it will not finish, and<br>
instead just sit there waiting for you to read that data, and you'll<br>
be getting into a very common race condision with subprocesses.<br>
<br>
What you really need is to do the reading in a thread, so the<br>
process can continue running. It might seem strange at first, but<br>
when there's a lot of data then *someone* needs to hold it, and the<br>
OS will hold only a very small amount (and for good reasons). Your<br>
thread will need to do just that accumulation (or it can just to the<br>
processing, whatever it is).<br>
</blockquote><div><br>After re-reading your example, I think I started to grok what you were doing on <a href="http://www.cs.brown.edu/pipermail/plt-scheme/2006-February/011953.html">http://www.cs.brown.edu/pipermail/plt-scheme/2006-February/011953.html</a>: <br>
<pre style="font-family: courier new,monospace; margin-left: 40px;">...<br>(define-values (in out) (make-pipe)) ... <br>...<br>(thread (lambda ()<br> (copy-port pout out)<br> (close-output-port out)<br> (subprocess-wait p)))</pre>
You first created a pipe for holding the accumulation, and then you started a thread to read the data from pout into pipe's out, and when out is closed the data gets piped to in (perhaps this is happening in the background without you have to close it too?), and finally the process exits... correct? But shouldn't the ports be closed after subprocess-wait? <br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
(You can also see "collects/mzlib/process.ss" for a very extensive<br>
solution.)<font color="#888888"><br></font></blockquote><div><br>Thanks for the pointer - time to learn the concurrency primitives in the module... ;) <br><br>Thanks,<br>yc<br><br></div></div>