[Gambas-devel] About process management

Benoit Minisini gambas at ...1...
Sat Mar 13 17:28:10 CET 2004


On Sunday 07 March 2004 11:28, Daniel Campos wrote:
> Hi Benoît (and company):
>
> When executing a program using EXEC, I always find a problem:
>
> I can not recover all stdout output from the process, as usually the
> process is closed by gambas before all data has been read from the
> gambas input pipe. Try, for example "Proceso1.tar.gz", this little
> program makes 'ls -l' on the home directory (change it for any other
> with a lot of files, if you have few files at home directory).
>
> You will see in the textarea that you receive just a fragment from
> the ls output, all the rest is lost (the final part).
>
>  I've been looking at the gbx_c_process.c file, and the final
> part of the output is beeing 'abandoned'. I've added a buffer
> in the process structure at "gbx_c_process.h" file, and I manage
> it in the "gbx_c_process.c" (my 'hackings' are marked between
> "/*<DCF*/ and /*DCF>*/ symbols), and I've seen I can recover
> the final part of the output and print it in the stdout, and buffer it
> into the process structure. (try "Proceso1" example using these files I
> provide)
>
>  My idea was to keep that data in the buffer, and send 'Read' events
> to let the user retrieve the rest of the information, extracting data
> from the buffer instead of the pipe when the process is already dead.
>
>  However I do not understand very well the process stream, so, at this
> moment I just send you that patched files, I suppose you can correct
> this "read bug" better than me :-)
>
>  If this bug is corrected, process management will be more useful for
> a lot of people, allowing to perform a lot of tasks using unix commands!
>
> Regards,
>
> Daniel Campos

Hi, Daniel,

I fixed this problem this way: when the interpreter receives the SIGCHLD 
signal telling him that the process died, then he raised "Read" and "Error" 
events until the everything is read.

Note that you read process output by doing a READ #LAST,Buf,Lof(LAST). It is 
syntactically logic, but it does not work as Lof(LAST) does not return 
anything valid. Because I can't know how many bytes I can read on the process 
output without effectively reading them. The good way of reading process 
output is doing a READ #LAST,Buf,-256 (or any number you want). It reads at 
most 256 characters in the string.

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the Devel mailing list