[Gambas-user] Blocking read from a Process you had to write to
Tobias Boege
taboege at gmail.com
Mon Mar 18 23:34:57 CET 2019
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
More information about the User
mailing list