How to stream logcat output line by line ? #88
-
I want to stream logs line by line and close when I got specific line. Currently, I manually open adb executable, but disadvantage, it kills adbclient. Dim info As New ProcessStartInfo With {
.FileName = AdbPath, 'Path.Combine(AdbPath, "adb.exe"),
.Arguments = "-s emulator-5555 shell logcat -s LogInterceptor:V",
.UseShellExecute = False,
.RedirectStandardOutput = True,
.CreateNoWindow = True
}
Dim P = Process.Start(info)
Using reader = P.StandardOutput
While Not reader.EndOfStream
Dim Line = reader.ReadLine()
End While
End Using How can I implement in AdvancedSharpAdbClient instead ? Public Function RunAdb(client As AdbClient, device As DeviceData, cmd As String) As String
Dim receiver As New ConsoleOutputReceiver()
client.ExecuteRemoteCommand(cmd, device, receiver)
Dim Out = receiver.ToString() 'receiver.ReadLine ?
receiver.Flush()
Return Out
End Function |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
Dim Client = New AdbClient()
Dim device = Client.GetDevices().FirstOrDefault()
Dim sink = Sub(L As LogEntry)
Console.WriteLine(L)
End Sub
Client.RunLogService(device, sink, LogId.System)
Console.ReadLine() Okay this works, it shows logging. Now two questions:
|
Beta Was this translation helpful? Give feedback.
-
@wherewhere I pasted sample code for future reference. Sub WaitForServer()
Dim Source As New CancellationTokenSource()
Dim Token As CancellationToken = Source.Token
Dim sink = Sub(Log As Object)
If Log.Tag.ToString() = "LogInterceptor" Then
If Log.Message.Contains("Response body") Then
Console.WriteLine(Log.Message)
Source.Cancel()
End If
End If
End Sub
Dim Service = Client.RunLogServiceAsync(Device, sink, Token, LogId.Crash, LogId.Events, LogId.Main, LogId.Radio, LogId.System)
Service.Wait()
End Function Thanks so much for the support. Cheers! |
Beta Was this translation helpful? Give feedback.
-
Now you can using foreach to enumerate the output lines by |
Beta Was this translation helpful? Give feedback.
It cannot use filter because the filter is not supported on
logcat -B
. You can filter it by yourself.