I try to get Shell output, but the Wait For never seems to fire, altough a TimeOut is set. I have this in my main code:
B4X:
Sub AppStart (Args() As String)
Start
StartMessageLoop
End Sub
Sub Start()
Wait For (Google.GetUsers("xxxxxxxxx.com")) Complete ()
Log("Done")
End Sub
I have a module named Google with a GetUsers resumable sub:
B4X:
Public Sub GetUsers(DomainName As String) As ResumableSub
Log("Starting GetUsers")
Dim sh As Shell
sh.Initialize("", "GAM", Array As String("print", "users", "domain", DomainName))
sh.RunWithOutputEvents(10000)
Wait For (sh) ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
If Success And ExitCode = 0 Then
Log("Worked")
Log(StdOut)
Else
Log("Error")
Log(StdErr)
End If
Log("GetUsers finished")
Return True
End Sub
I'm pretty sure the initialize is correct (I have used the GAM tool many times, this is the first time I wrote a method that actually needs to fetch a result)
Even if something is terrible wrong, I would expect the RunWithOutputEvents to timeout after 10 seconds and show something, but it doesn't.
The only log I get is Starting GetUsers. After that the code just keeps on running forever.
Is their something wrong with my Resumable Sub?
Thanks a lot.
1. Better to use Run instead of RunWithOutputEvents (I don't see that you are handling the StdOut / StdErr events).
2. You should always add a parameter when waiting for resumable subs:
B4X:
Wait For (Google.GetUsers("xxxxxxxxx.com")) Complete (Unused As Boolean)
3. You need to set the event name and catch the event correctly:
B4X:
sh.Initialize("sh",...
sh.Run(10000)
Wait For (sh) sh_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
1. Better to use Run instead of RunWithOutputEvents (I don't see that you are handling the StdOut / StdErr events).
2. You should always add a parameter when waiting for resumable subs:
B4X:
Wait For (Google.GetUsers("xxxxxxxxx.com")) Complete (Unused As Boolean)
3. You need to set the event name and catch the event correctly:
B4X:
sh.Initialize("sh",...
sh.Run(10000)
Wait For (sh) sh_ProcessCompleted(Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
Thanks @Erel for your reply, it does work now indeed.
I tend to not use (Unused As boolean) because I have plenty of them, and using Unused1, Unused2, Unused3 seems so redundant, I never had problems with it, are there edge cases where it can result in wrong behaviour?
I tend to not use (Unused As boolean) because I have plenty of them, and using Unused1, Unused2, Unused3 seems so redundant, I never had problems with it, are there edge cases where it can result in wrong behaviour?
I'll explain:
Wait For can be used to catch events and resumable subs.
By convention events signature is made of <event name prefix>_<event>.
JobDone signature comes from the very old HttpUtils 1 module.
Note that this has nothing to do with Wait For.
B4X:
Sub JobDone (j As HttpJob)
'compared to:
Sub sh_ProcessCompleted(...)