[Gambas-user] Pipe doesn't receive contents

Doriano Blengino doriano.blengino at ...1909...
Sat May 8 18:41:28 CEST 2010


Benoît Minisini ha scritto:
>> First you used buffered I/O, whereas PIPE in Gambas use non-buffered I/O.
>> Then you use fgetc(), which reads one character, whereas in Gambas the
>> code uses LINE INPUT, which is far more complex. So you are not comparing
>> the two same programs...
>>
>> Regards,
>>     
>
> And the same program as you written in Gambas works too:
>
>   Dim hFile As File
>   Dim iChar As Byte
>
>   hFile = Pipe "/tmp/FIFO1" For Input
>
>   Print "Now let's start:";; Eof(hFile)
>   
>   Do
>     Try iChar = Read #hFile As Byte
>     If Error Then 
>       ' Normally the error is "End of file"
>       Print Error.Text
>       Break
>     Endif
>     Print Chr$(iChar);
>   Loop
>
>   Print "That's it."
>   
I promise that this is my last email on this subject.

I did some research about eof() & pipes just because not only one, but 
two persons on this list said that eof() has no sense with pipes. It was 
not to say that gambas has glitches. Now, you are saying that the gambas 
code above runs just fine - and this, together with previous proofs, 
shows that eof works even with pipes.

About comparing two different programs: I chose to make a test in C 
because that way I was closer to the system, not knowing what cat(1) 
does, and not knowing what gambas does. Remember, I wanted to 
demonstrate that eof works.

I find a little surprising that you start to talk about buffered and 
unbuffered I/O, or things like reading one char at a time. Do you really 
think that this does matter? If so, thousands of unix program should be 
revised - but I don't think. It is also strange that in this last 
program you don't test for eof(), but for an error. Eof and errors are 
different. If you really want to demonstrate that your program works, 
use the normal eof(), like I did. Lastly, your explanation about eof in 
a previous email was misleading: "eof checks if the pipe is empty"; EOF 
should not do that, pipes and sockets can be empty (no data ready), but 
this is not an eof condition. Even when reading in unblocking mode, the 
return code for an eof is different from an EAGAIN.

Anyway, I am happy that the above program works: our friend Rolf can 
rely on it.

Regards,
Doriano




More information about the User mailing list