octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Re: New function proposal


From: michael . goffioul
Subject: RE: Re: New function proposal
Date: Thu, 15 Feb 2007 15:48:52 +0100

> Ok, I'm now compiling this. However, I'd like to add a unit test to the
> popen2 code. Taking the example code from popen2 and modifying it
> slightly I have a test like
 
I did some additional tests and found out that the problem isn't really
the fact that reading a non-blocking pipe always looks like an EOF
whether there's no input or the pipe is closed, but more the fact that
errno is not reset by the fgets call, such that you don't see any difference
when the actual EOF is reached. If you reset errno before calling fgets,
then it works with non-blocking pipes, except that you have to check
for EINVAL instead of EAGAIN.
 
[in, out, pid] = popen2 ("sort", "/R");
fputs (in, "these\\nare\\nsome\\nstrings\\n");
fclose (in);
EAGAIN = errno ("EINVAL");
done = false;
str = {};
idx= 0;
do
    errno (0);
    s = fgets (out);
    if (ischar (s))
        idx++;
        str{idx} = s;
    elseif (errno () == EAGAIN)
        sleep (0.1);
        fclear (out);
    else
        done = true;
    endif
until (done)
fclose (out);
assert(str,{"these\\r\\n","strings\\r\\n","some\\r\\n","are\\r\\n"})

Michael.
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]