[Gambas-user] Blocking read from a Process you had to write to

Jussi Lahtinen jussi.lahtinen at gmail.com
Tue Mar 19 00:11:37 CET 2019


I doubt this will satisfy you, but shell command has it ready for you.

Jussi

On Tue, Mar 19, 2019 at 12:35 AM Tobias Boege <taboege at gmail.com> wrote:

> On Mon, 18 Mar 2019, Tobias Boege wrote:
> > How is it done properly? I really just want an "Exec ... To sOut", but
> with
> > the option to pipe something into the process when it starts.
> >
>
> I found this one using a Read event and a global variable. At least
> it doesn't need explicit Waits with arbitrary delay values:
>
>   Private $sOut As String
>
>   Private Sub Run(aCmd As String[], sInput As String)
>     Dim hProc As Process
>
>     $sOut = ""
>     hProc = Exec aCmd For Read Write As "Process"
>     Write #hProc, sInput
>     hProc.CloseInput()
>     hProc.Wait()
>     Return $sOut
>   End
>
>   Public Sub Process_Read()
>     Dim sBuf As String
>
>     sBuf = Read #Last, -4096
>     $sOut &= sBuf
>   End
>
> I'm still curious if you can avoid the Read event. (I suppose if you're
> really clever you can avoid the global $sBuf by using the Process' Tag
> instead...) But still: is there a way to read a process imperatively as
> nicely as the Read event allows you to?
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190319/4d29856d/attachment-0001.html>


More information about the User mailing list