[Openmcl-devel] timely output from an external-process-output-stream
Paul Krueger
plkrueger at comcast.net
Wed Mar 23 10:01:44 PDT 2011
Try something like "fflush(stdout);" after your printf. I suspect that it's just being buffered on the output side.
On Mar 23, 2011, at 11:17 AM, Sol Swords wrote:
> Hi,
>
> I'm running an external program via run-program, and that program semi-regularly prints output that I'd like to see on the screen, but also save to operate on later. So I'm using :output :stream, reading from the stream using read-line, and both printing and saving the read strings:
>
> (let* ((extprog (ccl::run-program "./foox" nil
> :wait nil
> :input nil
> :output :stream))
> (out (ccl::external-process-output-stream prog))
> line ;; lines read from program output
> buf ;; saved program output
> (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))))
>
> But depending on the program, this actually sometimes ends up just sitting for a while after writing one "Waiting for line", and then dumping all the output when the program exits. So, for example, if foox is a little c program like this:
>
> #include <stdio.h>
> int main () {
> int i;
> for (i=0; i<5; i++) {
> printf("line %i\n", i);
> sleep(1);
> }
> return 0;
> }
>
> Then I get, as expected, the following output:
> Waiting for line
> line 0
> Waiting for line
> line 1
> Waiting for line
> line 2
> Waiting for line
> line 3
> Waiting for line
> line 4
> Waiting for line
> NIL
>
> But this output actually occurs all at once after the 5 seconds, instead of getting one new line every second. On the other hand, if I run "yes" instead, I get immediate output, and if I run foox with :output t, I also get immediate output (but then don't have a mechanism to save the strings.)
>
> Is there some way to ensure (perhaps by changing the behavior of the external program, but preferably instead changing something in the Lisp) that I get the program's output more frequently?
>
> Thanks,
> - Sol
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
More information about the Openmcl-devel
mailing list