I am spawning a process from Common Lisp program (gnuplot). I am able to establish input and output streams for the process. However, I have a problem reading from the output. The problem is that I want to try to read from the output, and if there is nothing there, well... do nothing for example.
(Basic problem: I want to read the result of the command show term
but I want to skip any other output that gnuplot might have produced before sending this command)
If I just use (read-line gnuplot-output nil :eof)
and there is nothing in output stream, it will not indicate :eof
(since the stream is still alive and something might appear there) and will just block until it has something to read (i.e. forever).
Is there are way to detect that there is nothing to read? At least, somehow safely time-out the attempt to read (i.e. it shouldn't pop a new line out of the stream once the time-out is reached)?
PS. I am using SBCL
read-char-no-hang
, you don't need to uselisten
. Also, collapsing variable bindings from an outerlet
/let*
to the innerdo
/do*
as you did in one of your edits hinders code readability and maintainability, only to save a few characters. Bothprogram
andoutput-stream
don't vary in the loop, so leaving them in an outerlet
/let*
would make that obvious. – Physostomous