I'm working on OpenLibX 7.0 and I'm wondering if it's possible to reroute a Shell's StdOut and StdErr events to a public variable in Class_Globals. My "Computer" module is attached.
B4X:
Dim Com as Computer
Com.Initialize
Com.Execute("java -version", True, False)
Log (Com.ReadAll)
So basically, I'm wanting to have the "ReadAll" variable in "Com" actually contain StdOut and StdErr so I can use it without having to write the output to a text file.
I think that your code only makes it more complicated to correctly use the Shell object. Maybe create a simple method that splits the arguments.
You should run the process and return the ShellSyncResult object. Otherwise you will need to run the process multiple times if you want to check the results.
@Erel
I have simplified the code to where my Execute method returns a map with the Shell's output.
Method 1:
B4X:
Dim Result As ShellSyncResult = ProcessShell.RunSynchronous(-1)
Dim M As
M.
M.Put("ExitCode", Result.ExitCode)
M.Put("Success", Result.Success)
M.Put("Output", Result.StdOut & Result.StdErr)
Return M
Method 2:
B4X:
Dim Result As ShellSyncResult = ProcessShell.RunSynchronous(-1)
Dim M As Map
M.Initialize
M.Put("ExitCode", Result.ExitCode)
M.Put("Success", Result.Success)
M.Put("Error", Result.StdErr)
M.Put("Output", Result.StdOut)
Return M
Method 1 works, but with Method 2, StdErr actually contains the output from "java -version". I don't mind using Method 1, but I would like to know what causes Method 2 to do what it does.
Though it would be easier, I want to use more than just the output. I also want to use the Success variable. Ex:
B4X:
Dim M As Map = P.Execute("command", True, False)
Dim Answer As Boolean = M.Get("Success")
If Answer Then
'Do stuff
Else
'Command wasn't successful.
End If