[Openmcl-devel] timely output from an external-process-output-stream
Sol Swords
sswords at centtech.com
Wed Mar 23 09:17:54 PDT 2011
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
More information about the Openmcl-devel
mailing list