[Gambas-user] PRINT #process Example

Dimitris Anogiatis dosida at ...626...
Tue Mar 3 00:40:34 CET 2009


Thanks for the quick reply Doriano,

I got it working after experimenting a bit with your suggested solutions :)

I tried using a timer but I soon found out that using the LINE INPUT from
within the Process_Read works way better.

Keep rockin :)

Regards,
Dimitris

On Mon, Mar 2, 2009 at 1:48 AM, Doriano Blengino <
doriano.blengino at ...1909...> wrote:

> Dimitris Anogiatis ha scritto:
> > hey guys
> >
> > I've read the documentation on Process_Read() but I can't find a way to
> > detect
> > when the process has stopped and it's waiting for an input; to my
> > understanding
> > I can provide that input with PRINT #Process, "input" but so far I
> haven't
> > found
> > a full example of how that is done.
> >
> > can someone augment the process_read example to show me where and how
> > the PRINT #process, "input" fits in the picture?
> >
> All the thing starts by invoking an external command:
>
>  PRIVATE hProc AS Process
>        ...
>  hProc = EXEC ["/bin/sh", "-c", "\"" & command & "\" load " &
> FMain.myfm_version] FOR INPUT OUTPUT AS "plugin"
>
> In the statement above an external command is invoked using /bin/sh, and
> passing it the command to execute along with its parameters.
> The clauses "FOR INPUT OUTPUT AS ..." are necessary to name an event which
> handles data received from standard output.
>
> At any time you can know the state of the external command peeking at hProc
> properties.
> You can also kill the command using "hProc.Kill".
>
> The event handler for reading is:
>
>
>    PUBLIC SUB plugin_read()
>
>      DIM st AS String
>
>      LINE INPUT #hProc, st
>
>      PRINT "Plugin: read "; st
>
>      pluginlastread.Add(st)
>
>    END
>
> The subroutine above is automatically invoked when a line can be read from
> the output of the command. This works when the output is made of entire
> lines, I am not sure what happens if a command does not output whole lines.
> At any time you can "print #hProc" to send data to the external process
> standard input.
> In my program I poll the hProc.State to see if the command is terminated or
> not; I think you can do it in the event handler, or outside (with a timer or
> something else).
>
> Also, I think that the input and output channels can be closed without
> issuing a Kill, and probably closing a channel also kills the external
> process, but I didn't try.
>
> At home I should have a small test program to demonstrates how pipes work.
> If you still need more info I can send you that project.
>
> Regards,
> Doriano
>
>
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco,
> CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the
> Enterprise
> -Strategies to boost innovation and cut costs with open source
> participation
> -Receive a $600 discount off the registration fee with the source code:
> SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list