[Openmcl-devel] timely output from an external-process-output-stream

Sol Swords sswords at centtech.com
Wed Mar 23 12:21:09 PDT 2011


Thanks for the help, Paul and Dietrich.  I also found this:
http://lists.freebsd.org/pipermail/freebsd-hackers/2008-May/024662.html
which basically says that the "script" utility can be used to get a program to 
act like it's talking to a terminal instead of a pipe, so:

(time (let* ((extprog (ccl::run-program "script"
                                         '("/dev/null" "-q" "-c" "./foox")
                                         :wait nil
                                         :input nil
                                         :output :stream :error :stream))
              (out (ccl::external-process-output-stream extprog))
              line buf (keep-going t))
         (loop while keep-going do
               (write-line "Waiting for line") (force-output)
               (setq line (read-line out nil)) ;; no eof-error-p
               (if line
                   (progn (push line buf)
                          (write-line line)
                          (force-output))
                 (setq keep-going nil)))))

Pretty strange, but it appears to basically work.

  - Sol


On 03/23/11 12:03, Diedrich Wolter wrote:
> Hi,
>
> the 'delay' occurs most likely since the output stream is not flushed.
> Just add the line fflush(stdout) to your C-program and your done. To the
> best of my knowledge, flushing behavior solely depends on the output
> device you write to and there's no programmatic way to change this
> (terminal devices tend to flush after \n, pipes generally don't).
>
>> #include <stdio.h>
>> int main () {
>> int i;
>> for (i=0; i<5; i++) {
>> printf("line %i\n", i);
> ---> fflush(stdout); <---
>
>> sleep(1);
>> }
>> return 0;
>> }
>
>
> Best,
> Diedrich
>
> --
> Diedrich Wolter
> dwolter at informatik.uni-bremen.de
> SFB/TR 8 Spatial Cognition, project R3-[Q-Shape]
>



More information about the Openmcl-devel mailing list