[Gambas-user] Help with SHELL and EXEC

Doriano Blengino doriano.blengino at ...1909...
Sun Oct 12 09:23:39 CEST 2008


Kari Laine ha scritto:
>
> I got interested this writing process input thing. I can read process output
> without problem. Although it seems that reading of the stdout will start
> only when process ends. I made a little filter program in C and a gambas
> project to try to use it but I can not get the wrriting work so that when
> written the filter would return something to gambas-project. This got to do
> something that same program cannot both write and read to process - or what?
> Well here they are if someone is also interested to test. I would be very
> great full for any advice how to write to certain process.
>   
If you look carefully at the docs about EXEC:

  [ _Process_ *=* ] *EXEC* _Command_ [ *WAIT* ] [ *FOR* { { *READ* | 
*INPUT* } | { *WRITE* | *OUTPUT* } } ] [ *AS* _Name_ ]

you'll notice that you can't specify both READ & WRITE --------^

I have also a big book about Linux programming and, when I first read 
that book, I was wondered because it said that you can't open a pipe 
both for reading and for writing. Doing such things is a completely 
different matter, it said.
Still I think that it should be possible with the right calls but, don't 
knowing what gambas does behind the scenes, the only thing I can say 
now, is that the syntax explanation does not permit that. But gambas 
happily lets you specify both READ & WRITE...

Then, reading more carefully, I noticed that the docs say: "if you 
specify INPUT & OUTPUT instead of READ & WRITE, then the process is 
executed inside a virtual terminal". Remembering that that book was 
talking, if I well remember, about virtual terminals to be necessary to 
do such things, I tried in gambas. And it works!

I attach the project, which uses "tr" as filter.
Run it, then click ToggleButton1; in the gambas console you will see 
what the program sends to tr, and in the textarea you will see what tr 
replies back to the program.

Cheers.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: doublepipe-0.0.1.tar.gz
Type: application/x-tgz
Size: 7966 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20081012/c40ce756/attachment.bin>


More information about the User mailing list