[Gambas-user] Help with SHELL and EXEC
Doriano Blengino
doriano.blengino at ...1909...
Sun Oct 12 18:18:34 CEST 2008
Benoit Minisini ha scritto:
>
> OK, I think I have understoood. The behaviour is normal (except the 'bad file
> descriptor' error message).
>
> Try that in a shell:
>
> $ cat | tr "a-z" "A-Z" > tr.out
>
> This is an equivalent of what you tried to do in your program. Some things are
> sent to the input of "tr" line by line, and the output is put somewhere
> (inside a file in that case).
>
> I looked inside the source code of tr, and this tool uses buffered output.
>
> So:
> - If the output of 'tr' is a terminal (this is the case when you use INPUT
> OUTPUT in Gambas), then 'tr' output is automatically flushed at each end of
> line.
> - Otherwise, output is flushed when the buffer is full, i.e. when 'tr' has
> 4096 bytes to write.
>
> You see that in the shell command above. While you have not entered at least
> 4096 bytes, nothing is write in the tr.out file.
>
> I hope I was clear!
>
> Regards,
>
Yes, things seem to be so.
I tried the project again, but writing 1024, or 256, or 128 bytes at a time.
It seems that the buffer is 1024 bytes: when writing chunks of 1024
bytes, the reply is instantaneous; when writing 256 bytes, it takes 4
writes before tr replies; when writing 128 bytes, it takes eight writes.
So, the buffer is 1024 bytes (on my system).
I also added a button to close the stream at will. After writing a
single byte, and nothing seen in the textArea, a "close #nProcess" makes
the buffer flushes in textarea, and the tr program finishes.
So, the last info to Kari is: don't forget to close the stream, and all
works as expected (except the bad file descriptor, you say).
Regards.
More information about the User
mailing list