[Gambas-user] Help with SHELL and EXEC
Benoit Minisini
gambas at ...1...
Sun Oct 12 16:15:50 CEST 2008
On dimanche 12 octobre 2008, Kari Laine wrote:
> On Sun, Oct 12, 2008 at 4:31 PM, Benoit Minisini <
>
> gambas at ...1...> wrote:
> > On dimanche 12 octobre 2008, Doriano Blengino wrote:
> > > Tell me what your tests say to you - this is very interesting because I
> > > did not try if that book was true or not.
> >
> > Strange behaviours.
> >
> > If I replace INPUT OUTPUT by READ WRITE, the process does not write to
> > its standard output anymore.
> >
> > But if I replace the "tr" program by "cat", then READ WRITE works as
> > expected.
> >
> > So there is something different in "tr" that prevents him to work with
> > the READ WRITE options.
> >
> > Moreover, sometimes the first write to the "tr" process fails (with a bad
> > file
> > descriptor error message).
> >
> > All that needs some investigation...
> >
> > To test whether either WRITE or OUTPUT works without READ or INPUT I made
> > a
>
> little filter which stores it input to output file.
> Here is the filter
> -------
> #include <stdio.h>
>
> int main()
> {
> int character;
> int lask;
> FILE *nHandle;
>
> printf("program started\n");
> nHandle=fopen("/home/kari/output.txt","w");
>
> character = getc(stdin);
>
>
> while(character != EOF)
> {
> //printf("%d",character);
> fputc(character,nHandle);
--> adds 'fflush(stdout);' there.
> character = getc(stdin);
> }
>
> close(nHandle);
>
> }
> -------------------------
FILE, stdin and stdout are buffered streams managed by the C library on top of
the read()/write() system calls.
If you don't use fflush(), then Gambas will not see anything until:
- A newline is written, in most cases (for example, a buffer on a terminal
output).
- The buffer is full (usually 4096 bytes).
The condition of automatic output buffer flush can be configured in the C
library with the setvbuf() function If I remember.
Gambas has the equivalent:
- If you open a file with READ/WRITE, you will use unbuffered streams, i.e.
the read()/write() system calls directly.
- If you open a file with INPUT/OUTPUT, you will use buffered streams, i.e.
the FILE structure and the fXXXX() functions of the C library. Then, you must
use the FLUSH instruction to ensure that buffered writes are sent to the
write() system call.
But the way file are buffered is not yet configurable.
Regards,
--
Benoit Minisini
More information about the User
mailing list