<div dir="ltr">I tried your code with this bash script:<div><br></div><div><div>#!/bin/sh</div><div>echo hi</div><div>sleep 1</div><div>echo bye</div></div><div><br></div><div style>and I saw the "hi" a bit before the "bye" and the results printout. Is it possible your script is not flushing its output?</div>
<div style><br></div><div style>Also I agree with Neil that process*/ports is going to be better in the general case: it is more flexible than system (but if system* works, that can be okay: it is only obviously better than process*).</div>
<div style><br></div><div style>Robby</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 16, 2013 at 5:36 PM, Nick Shelley <span dir="ltr"><<a href="mailto:nickmshelley@gmail.com" target="_blank">nickmshelley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you both for your responses.<div><br></div><div>I tried to get Robby's to work because it seemed a little simpler, but I think I'm having buffering problems. I could have completely misunderstood the proposed solution as well...</div>
<div><br></div><div>Here's the relavent code: </div><div><br></div><div><div> (define-values (in out) (make-pipe))</div><div> (define stdout (current-output-port))</div><div> (define string-port (open-output-string))</div>
<div> (thread (λ () (copy-port in stdout string-port)))</div><div> (thread (λ () (flush-output stdout)))</div><div> (parameterize ([current-output-port out])</div><div> (system <script-that-logs-to-console>))</div>
<div> (printf "~n~nresults: ~a~n" (get-output-string string-port))</div><div><br></div><div>What I get is nothing until the script finishes, then I get the log message from stdout followed by my "results: ..." message that contains a duplicate of the logs. This is exactly what I want except that I want the logs to the stdout port to print in real time. I added the flush-output thread as an attempt to get around buffering, but I'm obviously misunderstanding something because it still didn't work.</div>
</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 16, 2013 at 2:24 PM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I find that using make-pipe with copy-port works well. Often you need to create a thread that copies the data to the real port you want it to go to and then stdout (or whatever) and when you do that, you have to be careful to make sure ports get closed properly, or else you'll lose data, but it doesn't take much code and works well.<div>
<br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div>On Thu, May 16, 2013 at 3:12 PM, Nick Shelley <span dir="ltr"><<a href="mailto:nickmshelley@gmail.com" target="_blank">nickmshelley@gmail.com</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div dir="ltr">I have a script that runs some automated tests and logs the results to the console. The tests can take 10+ minutes, so logging steps to the console is informative. I'm using Racket to run the script with (system ...) and parse the logs and report pass/failure, but to do that I have to capture the logs. I spent about an hour in the port docs and can't figure out how to both log to the console and capture the logs in Racket for further processing (although I'm really good at missing the obvious).<div>
<br></div><div>My current workaround is to use the tee command when running the script and then read in and process the file afterwords, but I was wondering if there is a more direct way to do this in Racket.</div>
</div>
<br></div>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>