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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to